I recently started using ansible to automate some server administration tasks.
Its very cool and easy to learn/extend. One nice feature is the “facts” gathering. It will collect information about the host(s) and stores them in its internal variables. This is useful for conditional execution of tasks (see below) but also as a ad-hoc way to gather information like DMI information or the running kernel.
To see all “facts” known to ansible about the hosts, run:
$ ansible all -m setup
To execute tasks conditionally you can do something like this:
- name: install vmware packages action: apt pkg=open-vm-tools only_if: "'$ansible_virtualization_type' == 'VMware'"
Note that ansible 1.2+ has a different (and simpler) conditional called “when”.
Ansible is available in Ubuntu 12.04+ via:
$ sudo apt-get install ansible
It is also available in Debian unstable and testing.