Bookmark this page

Lab: Remote Execution

Enable and configure remote execution jobs, and use remote execution to run Ansible Playbooks on a content host.

Outcomes

  • Configure a managed host for remote execution.

  • Run remote execution jobs, including Ansible Playbooks.

  • Create job templates for multiple executions of remote commands on a content host.

Important

The comprehensive review labs are related exercises, and you can start with any lab in the sequence. If you reset your lab environment before your first comprehensive review lab, then you do not need to reset again. If you did not reset your lab environment after performing exercises from previous chapters, then you must reset your lab environment before starting any comprehensive review lab.

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

Specifications

  • Register the serverb system to the Finance organization by using the FinanceServers activation key.

  • Use a remote job to query the serverb system uptime.

  • Use the provided playbook-example-cr.yml Ansible Playbook to create the Custom banner job template. Execute the job on the serverb system.

  1. Register the serverb system to the Finance organization.

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

      [student@workstation ~]$ ssh student@serverb
      [student@serverb ~]$ sudo -i
      [sudo] password for student: student
      [root@serverb ~]#
    2. Install the client certificate package, katello-ca-consumer-latest.noarch.rpm, on the serverb system.

      [root@serverb ~]# dnf localinstall \
      http://satellite.lab.example.com/pub/katello-ca-consumer-latest.noarch.rpm
      ...output omitted...
    3. Register the serverb system to the Finance organization by using the FinanceServers activation key.

      [root@serverb ~]# subscription-manager register --org=Finance \
      --activationkey=FinanceServers
      The system has been registered with ID: 95424d51-69a1-4142-ad18-4453dc96364e
      The registered system name is: serverb.lab.example.com
      Installed Product Current Status:
      Product Name: Red Hat Enterprise Linux Server
      Status:       Subscribed
    4. Return to the workstation system as the student user.

      [root@serverb ~]# exit
      logout
      [student@serverb ~]$ exit
      logout
      Connection to serverb closed.
      [student@workstation ~]$
  2. Distribute the Satellite Server Foreman SSH keys to the serverb content host.

    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. Copy the Foreman SSH key to the serverb system. The key is at ~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub.

      [root@satellite ~]# ssh-copy-id -i \
      ~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub \
      root@serverb.lab.example.com
      ...output omitted...
      Are you sure you want to continue connecting (yes/no)? yes
      ...output omitted...
      root@servera.lab.example.com's password: redhat
      
      Number of key(s) added: 1
      ...output omitted...
  3. Run a remote command on the serverb content host.

    1. Log in to the Satellite Server web UI, https://satellite.lab.example.com, as the admin user with redhat as the password.

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

    3. Click HostsAll Hosts, and then click the serverb.lab.example.com link.

    4. Click Schedule Remote Job. Select Commands in the Job category field. Select Run Command - SSH Default in the Job template field.

    5. Enter uptime in the command field. Click Submit. Wait for the process to complete.

    6. To view the remote command output, scroll down and click the serverb.lab.example.com link. Your results should be similar to the following output.

      1: 15:30:22 up 2 days, 1 user, load average: 0.00, 0.00, 0.00
      2: Exit status: 0
  4. Use the provided playbook-example-cr.yml Ansible Playbook to create the Custom banner job template.

    1. Click HostsJob templates, and then click New Job Template. Enter Custom banner in the Name field.

    2. Locate the playbook-example-cr.yml Ansible file in the student home directory on the workstation system. In the Editor window, paste the content of the playbook-example-cr.yml file.

    3. Click Job. Remove the existing job category, and select Ansible Playbook from the Job category list. Select Ansible in the Provider Type field. Click Submit.

  5. Remotely execute the Custom banner job template on the serverb content host.

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

    2. Click Schedule Remote Job. Select Ansible Playbook for the Job category. Select Custom banner for the Job template field. Click Submit.

    3. To view the remote command output, scroll down and click the serverb.lab.example.com link. View the Ansible Playbook execution output.

  6. Verify that the serverb system banner now contains your custom message.

    1. Log in to the serverb system as the student user. View the custom banner. Return to the workstation system as the student user.

      [student@workstation ~]$ ssh student@serverb
      "Welcome to the RH403 course,
       Comprehensive Review chapter"
       Activate the web console with: systemctl enable --now cockpit.socket
      
      Register this system with Red Hat Insights: insights-client --register
      ...output omitted...
      [student@serverb ~]$ exit
      logout
      [student@workstation ~]$

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

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

Revision: rh403-6.11-3ad886e