Difference between revisions of "Ansible"
(31 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[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 | [[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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Ansible provides three main commands: | Ansible provides three main commands: | ||
+ | # <code>ansible-playbook</code> - to execute an Ansible playbook on the specified systems | ||
+ | # <code>ansible</code> - to execute an individual shell command or Ansible module on the specified systems | ||
+ | # <code>ansible-vault</code> - (optional) to encrypt or decrypt YAML files that Ansible uses. | ||
− | + | == Modules == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==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. | 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. | ||
− | + | == Example Commands == | |
− | + | # <code>ansible -m setup wiki.example.com</code> will show you all the ansible 'facts' (aka [[ansible_variables]]) about that host. | |
− | + | # <code>ansible all -m setup -a "filter=ansible_distribution*"</code> use a filter action to see specific variables | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | #<code>ansible | ||
− | |||
− | |||
− | |||
− | |||
− | #<code>ansible all -m setup -a | ||
− | |||
#<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]' | #<code>ansible -m debug -a "var=hostvars['wiki.example.com']" localhost</code> gives you the '[[ansible hostvars]]' | ||
− | #<code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks | + | # <code>ansible-playbook play1.yml play2.yml</code> Run multiple playbooks |
− | + | # <code>~/bin/ansible/contrib/inventory/digital_ocean.py --list --pretty --api-token TOKEN_HERE</code> use the DO api to list your droplets (dynamic inventory) | |
− | |||
− | |||
− | #<code>~/bin/ansible/contrib/inventory/digital_ocean.py --list --pretty --api-token TOKEN_HERE</code> use the DO api to list your droplets (dynamic inventory) | ||
− | |||
− | |||
− | |||
− | |||
− | ;You have 3 plays in one playbook. Will play 3 be able to reference facts registered in play 1?: | + | == Variables == |
− | :facts, yes, play vars, no | + | ; You have 3 plays in one playbook. Will play 3 be able to reference facts registered in play 1?: |
− | :vars associated to the host, persist, vars defined in the play, do not, set_facts, registered vars and gathered facts associate to the host so those do persist for the run | + | : facts, yes, play vars, no |
+ | : vars associated to the host, persist, vars defined in the play, do not, set_facts, registered vars and gathered facts associate to the host so those do persist for the run | ||
− | ==Playbooks== | + | == Playbooks == |
Ansible "[http://docs.ansible.com/playbooks.html Playbooks]" use an easy and descriptive language based on YAML. | Ansible "[http://docs.ansible.com/playbooks.html Playbooks]" use an easy and descriptive language based on YAML. | ||
− | + | == Targets == | |
− | |||
− | |||
− | ==Targets== | ||
Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack | Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack | ||
+ | == 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. However, when I ran my first <code>ansible-playbook digitalocean.yml</code>, I got an 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> | ||
+ | Clearly ansible is falling back to the OS installed version. After I ran <code>source ~/bin/ansible/hacking/env-setup</code>, then I was able to run my ansible playbook | ||
− | + | == Ansible with MediaWiki == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==Ansible with MediaWiki== | ||
https://github.com/Orain | https://github.com/Orain | ||
I've cloned the '[https://github.com/freephile/ansible-playbook.git ansible-playbook]' | I've cloned the '[https://github.com/freephile/ansible-playbook.git ansible-playbook]' | ||
− | ==Ansible with Drupal== | + | == Ansible with Drupal == |
− | + | * Jeff Geerling (geerlingguy) has his code on github https://github.com/geerlingguy/drupal-vm, and also a website http://www.drupalvm.com/. He's the author of Ansible for DevOps. The only problem I see with his code is that it installs everything from his own 'roles' (individual components) via the sharing site/mechanism called Ansible Galaxy. So, for example, phpMyAdmin comes from https://github.com/geerlingguy/ansible-role-phpmyadmin This is good in that he can make his system work, but it's bad in that you're getting all your bits from him and can't tweak any of it without manually checking each role for the code and instructions behind it so you know what you can set via variables and such. I'd rather see each of these roles contained in the project, community sourced, installed via git. | |
− | *Jeff Geerling (geerlingguy) has his code on github https://github.com/geerlingguy/drupal-vm, and also a website http://www.drupalvm.com/. He's the author of Ansible for DevOps. The only problem I see with his code is that it installs everything from his own 'roles' (individual components) via the sharing site/mechanism called Ansible Galaxy. So, for example, phpMyAdmin comes from https://github.com/geerlingguy/ansible-role-phpmyadmin This is good in that he can make his system work, but it's bad in that you're getting all your bits from him and can't tweak any of it without manually checking each role for the code and instructions behind it so you know what you can set via variables and such. I'd rather see each of these roles contained in the project, community sourced, installed via git. | ||
<pre> | <pre> | ||
geerlingguy.firewall | geerlingguy.firewall | ||
Line 217: | Line 66: | ||
</pre> | </pre> | ||
− | *on [https://www.digitalocean.com/community/tutorials/how-to-create-an-ansible-playbook-to-automate-drupal-installation-on-ubuntu-14-04 Digital Ocean] | + | * on [https://www.digitalocean.com/community/tutorials/how-to-create-an-ansible-playbook-to-automate-drupal-installation-on-ubuntu-14-04 Digital Ocean] |
− | ==Ansible in the cloud== | + | == Ansible in the cloud == |
Ansible has several core modules for working with various [http://docs.ansible.com/list_of_cloud_modules.html cloud providers]. These include | Ansible has several core modules for working with various [http://docs.ansible.com/list_of_cloud_modules.html cloud providers]. These include | ||
− | *Amazon | + | * Amazon |
− | *[[Digital Ocean]] http://docs.ansible.com/digital_ocean_module.html | + | * [[Digital Ocean]] http://docs.ansible.com/digital_ocean_module.html |
− | *[[Linode]] http://docs.ansible.com/linode_module.html | + | * [[Linode]] http://docs.ansible.com/linode_module.html |
− | *[[LXC]] | + | * [[LXC]] |
− | *OpenStack | + | * OpenStack |
− | ==Ansible on Fedora== | + | == Ansible on Fedora == |
The [https://fedoraproject.org/wiki/Fedora_Project_Wiki Fedora Project] uses Ansible in it's Infrastructure team, and they publish their whole setup https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/README | The [https://fedoraproject.org/wiki/Fedora_Project_Wiki Fedora Project] uses Ansible in it's Infrastructure team, and they publish their whole setup https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/README | ||
− | + | == Ansible Docs == | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==Ansible Docs== | ||
Some of the docs pages I've visited | Some of the docs pages I've visited | ||
− | *https://docs.ansible.com/ansible/playbooks_intro.html | + | * https://docs.ansible.com/ansible/playbooks_intro.html |
− | *https://docs.ansible.com/ansible/intro_inventory.html | + | * https://docs.ansible.com/ansible/intro_inventory.html |
− | *http://docs.ansible.com/playbooks_best_practices.html | + | * http://docs.ansible.com/playbooks_best_practices.html |
− | *http://docs.ansible.com/playbooks_loops.html | + | * http://docs.ansible.com/playbooks_loops.html |
− | *https://docs.ansible.com/ansible/playbooks_conditionals.html | + | * https://docs.ansible.com/ansible/playbooks_conditionals.html |
− | *https://docs.ansible.com/ansible/playbooks_startnstep.html | + | * https://docs.ansible.com/ansible/playbooks_startnstep.html |
− | *https://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse | + | * https://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse |
− | *http://docs.ansible.com/YAMLSyntax.html | + | * http://docs.ansible.com/YAMLSyntax.html |
− | *https://docs.ansible.com/ansible/become.html | + | * https://docs.ansible.com/ansible/become.html |
− | *https://docs.ansible.com/ansible/debug_module.html | + | * https://docs.ansible.com/ansible/debug_module.html |
− | *https://docs.ansible.com/ansible/playbooks_debugger.html (<code>strategy:debug</code>) | + | * https://docs.ansible.com/ansible/playbooks_debugger.html (<code>strategy:debug</code>) |
− | *https://docs.ansible.com/ansible/playbooks_conditionals.html#sts=The When Statement%C2%B6 | + | * https://docs.ansible.com/ansible/playbooks_conditionals.html#sts=The When Statement%C2%B6 |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | == | + | == Ansible References == |
+ | * http://tjelvarolsson.com/blog/taking-the-effort-out-of-server-configuration-using-ansible/ | ||
+ | * http://tjelvarolsson.com/blog/how-to-create-automated-and-reproducible-work-flows-for-installing-scientific-software/ < with Vagrant | ||
+ | * http://jpmens.net/2012/06/06/configuration-management-with-ansible/ | ||
+ | * [http://jinja.pocoo.org/docs/dev/ Jinja] - the template engine for Ansible | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
[[Category:Configuration Management]] | [[Category:Configuration Management]] | ||
[[Category:DevOps]] | [[Category:DevOps]] |
Revision as of 15:32, 15 September 2016
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
Ansible provides three main commands:
ansible-playbook
- to execute an Ansible playbook on the specified systemsansible
- to execute an individual shell command or Ansible module on the specified systemsansible-vault
- (optional) to encrypt or decrypt YAML files that Ansible uses.
Contents
Modules[edit | edit source]
Ansible comes with over 200 modules that you should get familiar with in order to use the system effectively.
Example Commands[edit | edit source]
ansible -m setup wiki.example.com
will show you all the ansible 'facts' (aka ansible_variables) about that host.ansible all -m setup -a "filter=ansible_distribution*"
use a filter action to see specific variablesansible -m debug -a "var=hostvars['wiki.example.com']" localhost
gives you the 'ansible hostvars'ansible-playbook play1.yml play2.yml
Run multiple playbooks~/bin/ansible/contrib/inventory/digital_ocean.py --list --pretty --api-token TOKEN_HERE
use the DO api to list your droplets (dynamic inventory)
Variables[edit | edit source]
- You have 3 plays in one playbook. Will play 3 be able to reference facts registered in play 1?
- facts, yes, play vars, no
- vars associated to the host, persist, vars defined in the play, do not, set_facts, registered vars and gathered facts associate to the host so those do persist for the run
Playbooks[edit | edit source]
Ansible "Playbooks" use an easy and descriptive language based on YAML.
Targets[edit | edit source]
Ansible can deploy to virtualization environments and public and private cloud environments including VMWare, OpenStack, AWS, Eucalyptus Cloud, KVM, and CloudStack
Installation[edit | edit source]
The preferred way to install is to just git clone
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. However, when I ran my first ansible-playbook digitalocean.yml
, I got an error message
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
Clearly ansible is falling back to the OS installed version. After I ran source ~/bin/ansible/hacking/env-setup
, then I was able to run my ansible playbook
Ansible with MediaWiki[edit | edit source]
https://github.com/Orain I've cloned the 'ansible-playbook'
Ansible with Drupal[edit | edit source]
- Jeff Geerling (geerlingguy) has his code on github https://github.com/geerlingguy/drupal-vm, and also a website http://www.drupalvm.com/. He's the author of Ansible for DevOps. The only problem I see with his code is that it installs everything from his own 'roles' (individual components) via the sharing site/mechanism called Ansible Galaxy. So, for example, phpMyAdmin comes from https://github.com/geerlingguy/ansible-role-phpmyadmin This is good in that he can make his system work, but it's bad in that you're getting all your bits from him and can't tweak any of it without manually checking each role for the code and instructions behind it so you know what you can set via variables and such. I'd rather see each of these roles contained in the project, community sourced, installed via git.
geerlingguy.firewall geerlingguy.git geerlingguy.apache geerlingguy.memcached geerlingguy.mysql geerlingguy.php geerlingguy.php-pecl geerlingguy.php-memcached geerlingguy.php-mysql geerlingguy.php-xdebug geerlingguy.php-xhprof geerlingguy.phpmyadmin geerlingguy.composer geerlingguy.drush geerlingguy.daemonize geerlingguy.mailhog geerlingguy.java geerlingguy.solr
Ansible in the cloud[edit | edit source]
Ansible has several core modules for working with various cloud providers. These include
- Amazon
- Digital Ocean http://docs.ansible.com/digital_ocean_module.html
- Linode http://docs.ansible.com/linode_module.html
- LXC
- OpenStack
Ansible on Fedora[edit | edit source]
The Fedora Project uses Ansible in it's Infrastructure team, and they publish their whole setup https://infrastructure.fedoraproject.org/cgit/ansible.git/tree/README
Ansible Docs[edit | edit source]
Some of the docs pages I've visited
- https://docs.ansible.com/ansible/playbooks_intro.html
- https://docs.ansible.com/ansible/intro_inventory.html
- http://docs.ansible.com/playbooks_best_practices.html
- http://docs.ansible.com/playbooks_loops.html
- https://docs.ansible.com/ansible/playbooks_conditionals.html
- https://docs.ansible.com/ansible/playbooks_startnstep.html
- https://docs.ansible.com/ansible/playbooks_roles.html#task-include-files-and-encouraging-reuse
- http://docs.ansible.com/YAMLSyntax.html
- https://docs.ansible.com/ansible/become.html
- https://docs.ansible.com/ansible/debug_module.html
- https://docs.ansible.com/ansible/playbooks_debugger.html (
strategy:debug
) - https://docs.ansible.com/ansible/playbooks_conditionals.html#sts=The When Statement%C2%B6
Ansible References[edit | edit source]
- http://tjelvarolsson.com/blog/taking-the-effort-out-of-server-configuration-using-ansible/
- http://tjelvarolsson.com/blog/how-to-create-automated-and-reproducible-work-flows-for-installing-scientific-software/ < with Vagrant
- http://jpmens.net/2012/06/06/configuration-management-with-ansible/
- Jinja - the template engine for Ansible