Use fact caching to speed up job execution and explore how to manage the fact cache.
Outcomes
Use fact caching in job templates.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command ensures that automation controller is installed and configured with any necessary resources created in previous exercises.
[student@workstation ~]$ lab start job-facts
Procedure 5.1. Instructions
Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.
Update the global job settings for automation controller to specify that cached facts are valid for one day (86,400 seconds).
Navigate to and click the link.
Click .
Enter 86400 in the field and then click .
Display the cached facts for hosts in the Dev inventory. Navigate to → and click the link for the host. Click the tab and notice that facts do not exist for the host.
Repeat for the host.
If you previously completed this exercise or if you perform the exercises in a different order, then facts might already be cached for the servera.lab.example.com and serverb.lab.example.com hosts.
Collect (or update) facts for hosts in the Dev inventory.
Navigate to → and click the icon for the job template.
Select and then click .
From the page, click . Select the Dev inventory, click , and then click . This job targets hosts in the Dev inventory using the refresh_fact_cache.yml playbook in the Fact Caching project. The job succeeds.
(Optional) Display the cached facts for hosts in the Dev inventory. Navigate to → and click the link for the host. Click the tab and notice that facts exist for the host.
Repeat for the host.
If you do not see host facts, then verify the Per-Host Ansible Fact Cache Timeout setting under → on the automation controller web UI. By default, the fact cache timeout is set to zero.
The lab command creates the Internal Web project and the Internal Web Access job template. The playbook used by the job template disables fact gathering, but it requires networking facts to create a custom firewall rule. The job template prompts for an inventory and then runs the playbook on hosts in the selected inventory. Update the job template so that it can use cached facts and then launch the job template.
Navigate to → and click the icon for the job template.
Select and then click .
From the page, click . Select the Dev inventory, click , and then click . Verify that it succeeds.
In addition to configuring a basic web server, the internal_apache_setup.yml playbook used by the job template only allows access to hosts on the 172.25.250.0/24 network.
The workstation.lab.example.com server contains two NICs. The eth0 NIC is on the same network as the servera.lab.example.com and serverb.lab.example.com servers. The virbr0 NIC is a virtual device on a separate network. Display the IP addresses assigned to the workstation.lab.example.com server.
[student@workstation ~]$ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:00:fa:09 brd ff:ff:ff:ff:ff:ff inet172.25.250.9/24brd 172.25.250.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::b250:fdb:4e16:ff7c/64 scope link noprefixroute valid_lft forever preferred_lft forever 3:virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000 link/ether 52:54:00:df:3a:fc brd ff:ff:ff:ff:ff:ff inet192.168.122.1/24brd 192.168.122.255 scope global virbr0 valid_lft forever preferred_lft forever ...output omitted...
Run the curl command to access http://servera.lab.example.com from the eth0 interface. Because the --interface option for the curl command must be run as the root user, use the sudo command with student as the password.
[student@workstation ~]$sudo curl --interface eth0 \>http://servera.lab.example.com[sudo] password for student:studentHost: servera.lab.example.com <br> Accessible by the 172.25.250.0/24 network.
Run the curl command to access http://servera.lab.example.com from the virbr0 interface. Use the -m3 option so that you do not have to wait long for the request to time out. The command fails because the firewall running on the servera.lab.example.com server rejects web requests coming from the 192.168.122.1/24 network.
[student@workstation ~]$sudo curl --interface virbr0 -m3 \>http://servera.lab.example.comcurl: (28) Connection timed out after 3000 milliseconds