Changes

Jump to navigation Jump to search
2,842 bytes added ,  00:37, 16 September 2016
Install, Modules, Best practices
[[wp:Ansible_(software)]] is an open-source software platform for configuring and managing computers. It combines multi-node software deployment, ad hoc task execution, and configuration management. Written in Python, it is packaged by [[RedHat]]. As of July 2016, we're using Ansible 2.2.0
== Installation ==
The preferred way to [http://docs.ansible.com/intro_installation.html install] is to just <code>git clone</code> the source. Having the source makes it easy to upgrade, and it's self-contained, plus best of all you get all the examples and contribs.
If you see this error message:
<pre>
Traceback (most recent call last):
File "/usr/local/bin/ansible-playbook", line 44, in <module>
import ansible.constants as C
ImportError: No module named ansible.constants
</pre>
Be sure to source the env-setup script
 
== Getting Started ==
You must source the environment setup script to begin using Ansible (assuming you are running from a git checkout) <code>source ~/bin/ansible/hacking/env-setup</code>
Ansible provides three main commands:
# <code>ansible-playbook</code> - to execute an Ansible playbook on the specified systems
== Modules ==
Ansible comes with [https://docs.ansible.com/ansible/modules_by_category.html over 200 modules] that you should get familiar with in order to use the system effectively.
 
 
There are a bunch of modules in Ansible, like the [https://docs.ansible.com/ansible/mysql_db_module.html MySQL module], the [https://docs.ansible.com/ansible/monit_module.html Monit module], or the [https://docs.ansible.com/ansible/file_module.html File module] and other interesting modules like jabber, mail, sendgrid, dpkg_selections, composer, yum, redhat_subscription, the [https://docs.ansible.com/ansible/authorized_key_module.html authorized_key module] for working with SSH keys, and a whole section of [https://docs.ansible.com/ansible/list_of_system_modules.html system modules].
 
 
You can use the '''command module''' (secure but simple) or the '''[https://docs.ansible.com/ansible/shell_module.html shell module]'''. The latter may be useful if you need to run bash explicitly (defaults to /bin/sh); or anytime you need $HOME and redirection.
 
 
 
== Example Commands ==
Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack
== Installation Best Practices ==The preferred way Use tags to organize your Ansible work Use caching (default is off) to be able to refer to host 'facts' without having to hit each host in a playbook. Use register of [httphttps://docs.ansible.com/intro_installationansible/playbooks_variables.html installvariables] is to just <code>git clone</code> the sourcecreate more 'facts'. Having the source makes it easy Results vary from module to module. Use -v to upgradesee possible values.  There is an order of precedence with [https://docs.ansible.com/ansible/playbooks_variables.html playbook variables], with role defaults the lowest priority and itextra vars the winner. The array notation is preferred over the dot notation for accessing variables.{{ ansible_eth0["ipv4"]["address"] }} over {{ ansible_eth0.ipv4.address }} because some keywords in Python would conflict Reserved words:* hostvars* group_names* groups* environemnt '''inventory_hostname'''s self-contained, plus best is the name of all you get all the examples and contribs. However, when I ran my first '''ansible_hostname''' is the discovered hostname  You can use a variables file to put sensitive data in a different file (one excluded from git).<codesource lang="yaml">ansible- hosts: all remote_user: root vars: favcolor: blue vars_files: -playbook digitalocean/vars/top_secret.yml</codesourceYou can use variables on the command line (and besides key=value pairs, I got an error message you can use json or yml)<presource lang="yaml">Traceback (most recent call last)--- - hosts:'{{ hosts }}' File "/usr/local/bin/ansible-playbook", line 44, in <module>remote_user: '{{ user }}' import ansible.constants as CImportError tasks: No module named ansible - ...constants</presource>Clearly ansible is falling back to the OS installed version. After I ran <code>source ~/bin/ansible/hacking/env-setupplaybook release.yml --extra-vars "hosts=vipers user=starbuck"</code> == Scope ==Ansible has 3 main scopes: '''Global''': this is set by config, environment variables and the command line'''Play''': each play and contained structures, then I was able vars entries, include_vars, role defaults and vars.'''Host''': variables directly associated to run my ansible playbooka host, like inventory, facts or registered task outputs
== Ansible with MediaWiki ==
4,558

edits

Navigation menu