Viewing available Ansible facts

When writing playbooks, you may want to perform different actions depending on what kind of machine you’re running against. Ansible provides facts about a machine that you can use to filter down to the actions you need.

These facts are unique to each machine, so sometimes it’s difficult to know what’s available. If you’re wondering about a machine, you can always use the ansible command line tool to view them all. The ones that you’re interested in will usually be prefixed with ansible_.

To view all available facts:

ansible all -i /path/to/inventory -m setup

If you’re only only interested in a certain section (e.g. which programming languages are installed on a machine) you can provide one of the keys from the result as an argument:

ansible all -i /path/to/inventory -m setup -a "filter=ohai_languages"

Michael is a polyglot software engineer, committed to reducing complexity in systems and making them more predictable. Working with a variety of languages and tools, he shares his technical expertise to audiences all around the world at user groups and conferences. You can follow @mheap on Twitter

Thoughts on this post

Leave a comment?

Leave a Reply