Ansible Facts
By default, the first step ansible does is to gather facts about the hosts it’s going to execute against. These facts can be used in variables for more complex plays. If you are concerned about performance, you disable fact gathering by setting gather_facts: false in the top section of the playbook.
Let’s run our first playbook to see the facts that are returned. First, have a look at playbooks/facts.yml, then execute it.
You can see that there are a LOT of values about the host returned by running facts. Some are more useful than others, but it’s good to know what’s at your disposal.
Copy the facts.yml playbook to netstat.yml. We are going to create a playbook that installs the net-tools package if we are on RHEL 9.
Edit the playbook and add the following line after the gather_facts: line:
Change first task from showing all the facts, to just the one we care about:
Then add a second task to install the package if we are on RHEL 9.
Execute the new playbook and see the results.
Looks like we missed a step. Edit the playbook again and add the following line after gather_facts to use sudo on the remote system to become root:
Re-run the playbook.