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.

3 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.

  2. áo lá cờ việt nam giá rẻ Says:

    áo lá cờ việt nam giá rẻ

    Ansible and the facts from the “setup” module | Michael Vogt's blog

Leave a Reply

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: