Gather Facts Against a Single Server With Ansible

This blog post will discuss how Ansible gathers facts against a single server using an ad-hoc command.

In Ansible, Ansible gathers facts about a server using the “setup” module. This is useful for gathering information about a single node in Ansible, and it can be used to gather information from one or more nodes. The setup module also has options for inspecting specific parts of the system, such as package versions, installed software packages, and operating systems.

About ansible facts

Ansible facts allow Ansible to collect information from your network devices so Ansible can monitor and/or control them. Ansible facts are a subset of Ansible data that Ansible gathers from modules that contain device-specific data, such as NetApp storage systems or Cisco networking gear. Ansible facts also include a variety of operating system and application-specific data gleaned from modules like yum, NetApp filer, or JBoss AS.

In Ansible 2.4, the ability to use Ansible facts was added, allowing Ansible to gather information from any Ansible-supported device on a local network.

Get Facts

In the following command, I gather facts from a machine called linuxazure. The machine is located in an inventory file called hosts.

ansible linuxazure -i hosts -m setup

Filter Results

To filter the results into a specific item, run the following command. Below I’m filtering out all the data and only displaying the IPv4 address of the hosts.

ansible linuxazure -i hosts -m setup -a "filter=ansible_all_ipv4_addresses*"