Bookmark this page

Guided Exercise: Improving Performance with Fact Caching

  • 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

  1. Navigate to https://controller.lab.example.com and log in as the admin user with redhat as the password.

  2. Update the global job settings for automation controller to specify that cached facts are valid for one day (86,400 seconds).

    1. Navigate to Settings and click the Job Settings link.

    2. Click Edit.

    3. Enter 86400 in the Per-Host Ansible Fact Cache Timeout field and then click Save.

  3. Display the cached facts for hosts in the Dev inventory. Navigate to ResourcesHosts and click the link for the servera.lab.example.com host. Click the Facts tab and notice that facts do not exist for the host.

    Repeat for the serverb.lab.example.com host.

    Note

    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.

  4. Collect (or update) facts for hosts in the Dev inventory.

    1. Navigate to ResourcesTemplates and click the Edit Template icon for the Refresh Fact Cache job template.

    2. Select Enable Fact Storage and then click Save.

    3. From the Details page, click Launch. Select the Dev inventory, click Next, and then click Launch. This job targets hosts in the Dev inventory using the refresh_fact_cache.yml playbook in the Fact Caching project. The job succeeds.

    4. (Optional) Display the cached facts for hosts in the Dev inventory. Navigate to ResourcesHosts and click the link for the servera.lab.example.com host. Click the Facts tab and notice that facts exist for the host.

      Repeat for the serverb.lab.example.com host.

      Important

      If you do not see host facts, then verify the Per-Host Ansible Fact Cache Timeout setting under SettingsJob Settings on the automation controller web UI. By default, the fact cache timeout is set to zero.

  5. 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.

    1. Navigate to ResourcesTemplates and click the Edit Template icon for the Internal Web Access job template.

    2. Select Enable Fact Storage and then click Save.

    3. From the Details page, click Launch. Select the Dev inventory, click Next, and then click Launch. Verify that it succeeds.

  6. 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.

    1. 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 addr
      1: 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
          inet 172.25.250.9/24 brd 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
          inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
             valid_lft forever preferred_lft forever
      ...output omitted...
    2. 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: student
      Host: servera.lab.example.com <br>
      Accessible by the 172.25.250.0/24 network.
    3. 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.com
      curl: (28) Connection timed out after 3000 milliseconds

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish job-facts

This concludes the section.

Revision: do467-2.2-08877c1