Bookmark this page

Lab: Working with Ansible Configuration Settings

  • Configure automation content navigator to use a specific image by default and then use it to examine the current Ansible configuration.

Outcomes

  • Configure automation content navigator by using an ansible-navigator.yml file.

  • Configure Ansible by using an ansible.cfg file.

  • Use the ansible-navigator command to review your current Ansible configuration.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command creates an Ansible project in the /home/student/config-review directory.

[student@workstation ~]$ lab start config-review

Procedure 4.3. Instructions

  1. Change to the /home/student/config-review directory for your Ansible project and configure the automation content navigator settings file to use the hub.lab.example.com/ee-supported-rhel8:latest image by default, and set the pull policy to missing.

    1. Change to the /home/student/config-review directory.

      [student@workstation ~]$ cd ~/config-review
    2. Edit the ~/config-review/ansible-navigator.yml automation content navigator settings file. Change the value of the image directive to hub.lab.example.com/ee-supported-rhel8:latest, and in the pull section change the value of the policy directive to missing.

      Use the following grep command to display lines that do not begin with a number sign. The output of the grep command displays the expected content after you modify the ansible-navigator.yml file:

      [student@workstation config-review]$ grep -v '^#' ansible-navigator.yml
      ---
      ansible-navigator:
        execution-environment:
          enabled: True
          image: hub.lab.example.com/ee-supported-rhel8:latest
          pull:
            policy: missing
        logging:
          level: critical
        playbook-artifact:
          enable: True
  2. Because the install-web.yml playbook requires prompting for the privilege escalation password, you must disable creating playbook artifacts. Configure the automation content navigator settings file to disable creating playbook artifacts.

    1. Edit the ~/config-review/ansible-navigator.yml automation content navigator settings file. In the playbook-artifact section, change the value of the enable directive to False.

      The output of the grep command displays the expected content after you modify the ansible-navigator.yml file:

      [student@workstation config-review]$ grep -v '^#' ansible-navigator.yml
      ---
      ansible-navigator:
        execution-environment:
          enabled: True
          image: hub.lab.example.com/ee-supported-rhel8:latest
          pull:
            policy: missing
        logging:
          level: critical
        playbook-artifact:
          enable: False
  3. Use automation content navigator to determine how to specify the maximum number of forks Ansible uses to execute tasks on target hosts. Identify the name of the variable and to which section the variable belongs. Modify the ~/config-review/ansible.cfg Ansible configuration file to set the maximum number of forks to 15. Use automation content navigator to verify the changes.

    1. Run the ansible-navigator config command with no arguments.

      [student@workstation config-review]$ ansible-navigator config
      
          Name                            Default Source  Current
        0│Action warnings                 True    default True
        1│Agnostic become prompt          True    default True
        2│Allow world readable tmpfiles   True    default False
        3│Ansible connection path         True    default None
      ...output omitted...
    2. Type :f forks and then press Enter to filter the configuration settings for the forks pattern.

        Name                         Default          Source     	 Current
      0│Default forks                True             default      5
    3. Press 0 to inspect the Default forks configuration.

      Default forks (current/default: 5)
       0│---
       1│current_config_file: /home/student/config-review/ansible.cfg
       2│current_value: 5
       3│default: true
       4│default_value: 5
       5│description: Maximum number of forks Ansible will use to execute tasks on tar
       6│env:
       7│- name: ANSIBLE_FORKS
       8│ini:
       9│- key: forks  1
      10│  section: defaults  2
      11│name: Default forks
      12│option: DEFAULT_FORKS
      13│source: default
      14│type: integer
      15│via: default

      1

      The forks key matches the name of the variable in the ansible.cfg file.

      2

      The defaults section matches the name of the section that the variable belongs to in the ansible.cfg file.

      Exit from ansible-navigator by pressing ESC twice.

    4. Edit the ~/config-review/ansible.cfg Ansible settings file and change the forks setting to 15.

      The following grep command does not display lines that begin with a number sign, blank lines, and lines that begin with a semicolon. The output of the grep command displays the expected content after you modify the ansible.cfg file:

      [student@workstation config-review]$ grep -Ev '^#|^$|^;' ansible.cfg
      [defaults]
      forks=15
      inventory = inventory
      [privilege_escalation]
      ...output omitted...
    5. To verify the setting, run the ansible-navigator config command with no arguments.

      [student@workstation config-review]$ ansible-navigator config
      
          Name                            Default Source  Current
        0│Action warnings                 True    default True
        1│Agnostic become prompt          True    default True
        2│Allow world readable tmpfiles   True    default False
        3│Ansible connection path         True    default None
      ...output omitted...
    6. Type :f forks and then press Enter to filter the configuration settings for the forks pattern.

        Name            Default  Source                                       Current
      0│Default forks   False    /home/student/config-review/ansible.cfg      15

      Exit from ansible-navigator by pressing ESC.

  4. Use the ansible-navigator command with the -m stdout and --ask-become-pass options to run the install-web.yml playbook. When prompted, enter student for the privilege escalation password. Verify that the playbook runs successfully.

    1. Use the ansible-navigator command with the -m stdout and --ask-become-pass options to run the install-web.yml playbook.

      [student@workstation config-review]$ ansible-navigator run install-web.yml \
      > -m stdout --ask-become-pass
      BECOME password: student
      
      PLAY [Install web server] ******************************************************
      
      TASK [Gathering Facts] *********************************************************
      ok: [servera.lab.example.com]
      
      TASK [Install httpd package] ***************************************************
      changed: [servera.lab.example.com]
      
      PLAY RECAP *********************************************************************
      servera.lab.example.com    : ok=2    changed=1    unreachable=0    failed=0  ...

Evaluation

As the student user on the workstation machine, use the lab command to grade your work. Correct any reported failures and rerun the command until successful.

[student@workstation ~]$ lab grade config-review

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 config-review

This concludes the section.

Revision: do374-2.2-82dc0d7