In this review, you will install Ansible on workstation, use it as a control node, and configure it for connections to the managed hosts servera and serverb. Use ad hoc commands to perform actions on managed hosts.
Outcomes
You should be able to:
Install Ansible.
Use ad hoc commands to perform actions on managed hosts.
Log in to workstation as student using student as the password.
On workstation, run the lab review-deploy start command. This script ensures that the managed hosts, servera and serverb, are reachable on the network. The script creates a lab subdirectory named review-deploy in the student's home directory.
[student@workstation ~]$lab review-deploy start
Procedure 10.1. Instructions
Install Ansible on workstation so that it can serve the control node.
On the control node, create an inventory file, /home/student/review-deploy/inventory, containing a group called dev. This group should consist of the managed hosts servera.lab.example.com and serverb.lab.example.com.
Create the Ansible configuration file in /home/student/review-deploy/ansible.cfg. The configuration file should reference the /home/student/review-deploy/inventory inventory file.
Execute an ad hoc command using privilege escalation to modify the contents of the /etc/motd file on servera and serverb to contain the string Managed by Ansible\n. Use devops as the remote user.
[student@workstation review-deploy]$ansible dev -m copy \>-a 'content="Managed by Ansible\n" dest=/etc/motd' -b -u devopsservera.lab.example.com | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "checksum": "4458b979ede3c332f8f2128385df4ba305e58c27", "dest": "/etc/motd", "gid": 0, "group": "root", "md5sum": "65a4290ee5559756ad04e558b0e0c4e3", "mode": "0644", "owner": "root", "secontext": "unconfined_u:object_r:etc_t:s0", "size": 19, "src": "/home/devops/.ansible/tmp/...output omitted...", "state": "file", "uid": 0 } serverb.lab.example.com | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/libexec/platform-python" }, "changed": true, "checksum": "4458b979ede3c332f8f2128385df4ba305e58c27", "dest": "/etc/motd", "gid": 0, "group": "root", "md5sum": "65a4290ee5559756ad04e558b0e0c4e3", "mode": "0644", "owner": "root", "secontext": "system_u:object_r:etc_t:s0", "size": 19, "src": "/home/devops/.ansible/tmp/...output omitted...", "state": "file", "uid": 0 }
Execute an ad hoc command to verify that the contents of the /etc/motd file on servera and serverb are identical.