Ansible and the facts from the “setup” module

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.

About these ads

2 Responses to “Ansible and the facts from the “setup” module”

  1. Mxx Says:

    Ansible is not available from the default Ubuntu repos(yet?). You have to install some custom PPA which provides it.

    • mvogt Says:

      Yeah, its not part of the normal repo, but it is available via the {precise,quantal,raring}-backports repository. I should have mentioned that in the post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: