Print Facts of an Ansible Managed Host or LocalHost

This post will show you how to print all the variables that Ansible gathers from a remote machines that are known as fact using the discovery stage.

Ansible Facts

The Ansible facts are the foundations for understanding and evaluating remote machines and are also used for many conditions (when) when making logical decisions.

Setup Module

To gather facts on a single machine that is in the inventory, we use the setup module with an Ansible Ad-Hoc command as shown below. (hosts is the name of my inventory)

ansible ubuntu -m setup -i hosts

To run the same command on your localhost, use the following command without the -i for inventory.

ansible localhost -m setup

To extract a single value from the Ansible facts, simply use the following comamnd, in the example below I’m extracting the IP address of the host only.

ansible ubuntu -m setup -a 'filter=ansible_all_ipv4_addresses' -i hosts 

Success! You're on the list.

Leave a Reply

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