Bookmark this page

Guided Exercise: Configure Ansible Remote Execution

Configure the use of an Ansible Role on a Satellite Server.

Outcomes

  • Install an additional Ansible Role on the Satellite Server.

  • Customize and test an Ansible Role by using remote execution.

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

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start remote-configure

Instructions

The Operations system administration team uses Ansible Playbooks. A system administrator created a playbook that can modify a system banner, packaged the files in a compressed archive, and placed the archive on the satellite system. This exercise practices the same procedure as to install archived playbooks and roles that are downloaded from the Ansible Galaxy website.

  1. Log in to the satellite system as the student user and switch to the root user.

    [student@workstation ~]$ ssh student@satellite
    [student@satellite ~]$ sudo -i
    [sudo] password for student: student
    [root@satellite ~]#
  2. The ansible-role.tgz archive is in the root user's home directory. Create the motd role by using the extracted files from the ansible-role.tgz archive. Build the role in the default /etc/ansible/roles/ directory.

    1. Extract the files from the archive.

      [root@satellite ~]# tar xzvf ansible-role.tgz
      main.yaml
      motd.j2
    2. View the contents of each file.

      [root@satellite ~]# cat main.yaml
      - name: New /etc/motd file
        template:
          src: motd.j2
          dest: /etc/motd
          mode: 644
          owner: root
          group: root
      [root@satellite ~]# cat motd.j2
      This example configuration uses Ansible and Satellite to create the /etc/motd file for the RH403 course.
      
      This message uses a variable passed from Satellite: {{ new_var }}
    3. Create the motd role subdirectories, and then copy each file into the correct subdirectory. The main.yml file is a task playbook, and the motd.j2 file is a Jinja2 template.

      [root@satellite ~]# mkdir -p /etc/ansible/roles/motd/{tasks,templates}
      [root@satellite ~]# cp main.yaml /etc/ansible/roles/motd/tasks
      [root@satellite ~]# cp motd.j2 /etc/ansible/roles/motd/templates
  3. Log in to the Satellite Server web UI, https://satellite.lab.example.com, as the admin user with redhat as the password.

  4. In the upper-left corner of the web page, set the organization to Operations. Set the location to Any Location.

  5. Import the motd Ansible Role into the Satellite Server and configure the new_var Jinja2 template variable.

    1. Click ConfigureRoles, and then click Import from satellite.lab.example.com. Click the checkbox for the motd role and click Submit.

    2. Click ConfigureVariables, and then click New Ansible Variable. Complete the fields in the following table and then click Submit to create the variable.

      FieldDescription
      Key new_var
      Ansible Role motd
      Override Checked
      Default Value Hello from the RH403 course.
  6. Assign the motd role to the servera system.

    1. Click HostsAll Hosts, and then click the servera.lab.example.com link. Click Edit.

    2. Click the Ansible Roles tab. Click the plus sign (+) next to the motd role to assign the role to the servera system. Click Submit.

  7. Use remote execution to run the motd role to customize the servera system banner.

    1. Click HostsAll Hosts. Select the checkbox for servera.lab.example.com. Select Run all Ansible roles from the Select Action list.

    2. On the Overview tab, monitor the remote execution status. Wait for the process to complete. To view the remote command output, scroll down and click the servera.lab.example.com link.

    3. Log in to the servera system, and verify that the role customized the system banner.

      [student@workstation ~]$ ssh student@servera
      Welcome to my new customized server
      This example configuration uses Ansible and Satellite to create the /etc/motd file for the RH403 course.
      
      This message uses a variable that is passed from Satellite: Hello from the RH403 course.
      ...output omitted...
    4. Return to the workstation system as the student user.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$

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 remote-configure

Revision: rh403-6.11-3ad886e