Configure a host to enable remote execution, and test remote execution by using an ad hoc job.
Outcomes
Enable remote execution by distributing the Foreman SSH keys.
Run ad hoc commands on a content host 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-run
Instructions
Copy the Foreman SSH keys from each Capsule Server to the content host that is the remote execution target.
Satellite Server can delegate any Capsule Server that is authorized to provide remote execution to content hosts in managed locations. Copy the required Foreman SSH public keys from each authorized Capsule Server, including the integrated Capsule Server on the Satellite Server, to each content host that can be a remote execution target.
Log in to the capsule system as the student user and switch to the root user.
[student@workstation ~]$ssh student@capsule[student@capsule ~]$sudo -i[sudo] password for student:student[root@capsule ~]#
Copy the Capsule Server's Foreman SSH public key to the servera content host.
Find the public key in the foreman-proxy user's SSH configuration on the capsule system.
[root@capsule ~]#ls ~foreman-proxy/.ssh/id_rsa_foreman_proxy id_rsa_foreman_proxy.pub [root@capsule ~]#ssh-copy-id -i \ ~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub \ root@servera.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:redhatNumber of key(s) added: 1 ...output omitted...
Use the foreman-proxy identity to test the root@servera account for passwordless access from the capsule system.
If the public key was successfully copied, then you can access the account without a password prompt.
You might still be prompted to establish the authenticity of the remote host by continuing to connect.
If you are prompted for a password, then diagnose and fix the issue.
[root@capsule ~]#ssh -i ~foreman-proxy/.ssh/id_rsa_foreman_proxy root@servera...output omitted... Are you sure you want to continue connecting (yes/no/[fingerprint])?yes...output omitted... [root@servera ~]#
Return to the workstation system as the student user.
Log in to the satellite server as the student user and switch to the root user.
[root@servera ~]#exitlogout [root@capsule ~]#exitlogout [student@capsule ~]$exitlogout [student@workstation ~]$ssh student@satellite[student@satellite ~]$sudo -i[sudo] password for student:student[root@satellite ~]#
Copy the Satellite Server's Foreman SSH public key to the servera content host.
Find the public key in the foreman-proxy user's SSH configuration on the satellite system.
The ssh-copy-id command might warn that "All keys were skipped because they already exist on the remote system."
You can safely skip this ssh-copy-id step, because the public key was copied in a previous exercise.
[root@satellite ~]#ls ~foreman-proxy/.ssh/id_rsa_foreman_proxy id_rsa_foreman_proxy.pub [root@satellite ~]#ssh-copy-id -i \ ~foreman-proxy/.ssh/id_rsa_foreman_proxy.pub \ root@servera.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:redhatNumber of key(s) added: 1 ...output omitted...
Use the foreman-proxy identity to test the root@servera account for passwordless access from the satellite system.
If the public key was successfully copied, then you can access the account without a password prompt.
You might still be prompted to establish the authenticity of the remote host by continuing to connect.
If you are prompted for a password, then diagnose and fix the issue.
[root@satellite ~]#ssh -i ~foreman-proxy/.ssh/id_rsa_foreman_proxy root@servera...output omitted... Are you sure you want to continue connecting (yes/no/[fingerprint])?yes...output omitted... [root@servera ~]#
Exit the servera system, but keep open the terminal on the satellite system.
[root@servera ~]# exit
logout
[root@satellite ~]#Log in to the Satellite Server web UI, https://satellite.lab.example.com, as the admin user with redhat as the password.
In the upper-left corner of the web page, set the organization to Operations.
Set the location to Any Location.
From the Satellite web UI, run an ad hoc command remotely on the servera system.
Click → , and then click . Click .
Select Commands in the field.
Select Run Command - SSH Default in the field.
Enter uptime; hostname; whoami in the field.
Select Execute now from the choices.
Click .
On the tab, monitor the remote execution status. Wait for the process to complete. To view the remote command output, scroll down and click the link. Your results should be similar to the following output.
1: 04:03:39 up 33 min, 1 user, load average: 0.08, 0.02, 0.01 2: servera.lab.example.com 3: root 4: Exit status: 0
Using the hammer command, run the same commands as a remote execution job from the satellite server.
Using the terminal open on the satellite system, create a remote job for the ad hoc commands.
Because the default schedule is Execute now, the job runs immediately.
[root@satellite ~]# hammer job-invocation create \
--job-template "Run Command - SSH Default" \
--search-query "name = servera.lab.example.com" \
--inputs command="uptime; hostname; whoami"
Job invocation 2 created
[....................................................................] [100%]
1 task(s), 1 success, 0 failView the remote job output. Set the job ID value from the previous command.
[root@satellite ~]# hammer job-invocation output \
--id 2 --host servera.lab.example.com
04:10:51 up 40 min, 1 user, load average: 0.00, 0.00, 0.00
servera.lab.example.com
root
Exit status: 0From the Satellite web UI, run a remote Ansible ad hoc command on the servera system.
Click → , and then click the link. Click .
Select Ansible Commands in the field.
Select Run Command - Ansible Default in the field.
Enter df -h in the field.
Select Execute now from the choices.
Click .
On the tab, monitor the remote execution status. Wait for the process to complete. To view the remote command output, scroll down and click the link. Your results should be similar to the following output.
...output omitted... TASK [debug] ************************************** ok: [servera.lab.example.com] => { "out": { "changed": true, "cmd": "df -h\n", "delta": "0:00:00.008262", ...output omitted...
Using the hammer command, run the same Ansible commands as a remote execution job from the satellite server.
Using the terminal that is open on the satellite system, create a remote job for the ad hoc commands.
Because the default schedule is Execute now, the job runs immediately.
[root@satellite ~]# hammer job-invocation create \
--job-template "Run Command - Ansible Default" \
--search-query "name = servera.lab.example.com" \
--inputs command="df -h"
Job invocation 4 created
...output omitted...
TASK [debug] **************************************
ok: [servera.lab.example.com] => {
"out": {
"changed": true,
"cmd": "df -h\n",
"delta": "0:00:00.008262",
...output omitted...View the remote job output. Set the job ID value from the previous command.
[root@satellite ~]# hammer job-invocation output \
--id 4 --host servera.lab.example.com
...output omitted...Create a job template with the playbook-example.yml Ansible Playbook from the student home directory on workstation.
The playbook replaces a default system banner with a custom message.
Click → , and then click .
Enter My new custom banner in the field.
On the tab, in the upper-right corner of the Editor tool, click .
Select the /home/student/playbook-example.yml file, and then click .
Click the tab, and then click .
The playbook expects you to create a banner_var variable that contains your custom message at job invocation.
Enter banner_var in the field.
Click the tab.
In the field, clear the existing entry, and then select Ansible Playbook from the list.
Select Ansible in the field.
Click to save the job template.
Use the My new custom banner job template to run a remote execution job to customize the banner on the servera system.
Click → , and then click the link. Click .
Select Ansible Playbook in the field.
Select My new custom banner in the field.
Enter Welcome to my new customized server in the field.
Click .
On the tab, monitor the remote execution status. Wait for the process to complete. To view the remote command output, scroll down and click the link. View the Ansible Playbook execution output.
Return to the workstation system as the student user.
Log in to the servera system as the student user to view the custom banner.
When complete, return to the workstation system as the student user.
[root@satellite ~]#exitlogout [student@satellite ~]$exitlogout [student@workstation ~]$ssh student@serveraWelcome to my new customized server ...output omitted... [student@servera ~]$exitlogout [student@satellite ~]$