Here is the adhoc script I came up with for task 2.
#!/bin/bash
ansible ansible2 --become-user root -m user -K --ask-become-pass --become -a "name=automation state=present groups=wheel"ansible ansible3 --become-user root -m user -K --ask-become-pass --become -a "name=automation state=present groups=wheel"ansible ansible4 --become-user root -m user -K --ask-become-pass --become -a "name=automation state=present groups=wheel"ansible ansible5 --become-user root -m user -K --ask-become-pass --become -a "name=automation state=present groups=wheel"ansible all:!localhost -m file -K --ask-become-pass --become --become-user root -a "path=/home/automation/.ssh state=directory mode='0755'"ansible all:!localhost -m file -K --ask-become-pass --become --become-user root -a "path=/home/automation/.ssh state=directory mode='0755'"ansible all:!localhost -m lineinfile -K --ask-become-pass --become --become-user root -a "path=/home/automation/.ssh/authorized_keys state=present create=true line='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCucgpRJSz8pNX3MgjAdRLJA3FHmrNconvssiO0sgtC6nvgO4PTcVQYdBTHeATPJkXRTHdn8GKZnDx7fRrI4WqbqztmtYRPk24QZJ2AZUgoBHsYwge+aNFFKfcEdY2D9dIQQQZl8GpmTnlcSzkbB0bAwaG0ezmmSr63V0nPh62ITQ/ipIy7IMJNuKc9pzus/FhTVI6J6RVbe7u6go4PTsyIAYQGqtvmV0c7g4s6tYuriBwQkeQYj38BopxAak9jCrs2rUm5wIwsA4sIpI3zj4/eHXGH19tklVZsuJgpXbV8F+eJVHCwj9sTCMYFasElTfNB6cwcgjV+DbOMLhaa9kDUa8p8xoXshDzK6P0ACd5UD9ZNYbfaD9M0xcHC8YtmPmaHwMrfnbw6ki91Z3AMGSolY4lY8SP7wkgBpwOKZqwOfDBdGCFYd002zeKwpFeSxWUPNpnXfYZ4fGufWAxpMX0i8h0ia91kVIlkzhdEB3sZkG1L80roBFRSKvm8TOGswX0='"ansible all:!localhost -m lineinfile -K --ask-become-pass --become --become-user root -a "path=/etc/sudoers state=present regexp='^%wheel' line='%wheel ALL=(ALL) NOPASSWD: ALL'"
Task 3: File content
This task was pretty straightforward.
---- name:motd message for Proxy Serversbecome:yeshosts:proxytasks:- name:Add text to motd proxy serverslineinfile:path:/etc/motdline:"Welcome to HAProxy server"- name:motd message for web Serversbecome:yeshosts:webserverstasks:- name:Add text to motd webserverlineinfile:path:/etc/motdline:"Welcome to Apache server"- name:motd message for database Serversbecome:yeshosts:databasetasks:- name:Add text to motd database serverslineinfile:path:/etc/motdline:"Welcome to MySQL server"
Task 4: Configure sshd
Another easy one. Just open up the sshd_config file on the target host to see what to regex.
I added the user password as plain text at first. Then remembered later this needed to be stored as an MD5 hash. Luckily, the ansible-doc user document had a link to directions for generating the hashed password.
Task 6: Users and groups
This is when I first had to leave official documentation for help. The answer actually existed in the documentation but I didn’t know what I was searching for. In this task, you need a way to match user id’s based on the number that the id begins with.
I spent a full hour on this task before I ran for help..
The regex_search function is how I solved the problem:
Another easy one! The cron module documentation is great here.
[automation@ansible-control plays]$ cat regular_tasks.yml ---- name:cron for proxy servershosts:proxybecome:yestasks:- name:append date to logcron:name:"time"minute:0job:"date >> /var/log/time.log"user:root
Task 8: Software repositories
This task is dated and later tasks will fail because of it. This shouldn’t be a problem during the actual exam. Just follow examples in ansible-doc yum_repository.