Question : The Nautilus DevOps team is testing various Ansible modules on servers in Stratos DC. They're currently focusing on file creation on remote hosts using Ansible. Here are the details:
a. Create an inventory file ~/playbook/inventory on jump host and add all app servers in it.
b. Create a playbook ~/playbook/playbook.yml to create a blank file /opt/opt.txt on all app servers.
c. The /opt/opt.txt file permission must be 0755.
d. The user/group owner of file /home/web.txt must be tony on app server 1, steve on app server 2 and banner on app server 3.
Note: Validation will execute the playbook using the command ansible-playbook -i inventory playbook.yml, so ensure the playbook functions correctly without any additional arguments.
Please Note :- Perform the below commands based on your question server, user name & other details might differ . So please read task carefully before executing. All the Best 👍
1. Go through the folder mentioned in task and verified the playbook
ls -l /home/thor/playbook/
2. Create a inventory file and add the app server's as per task.
thor@jumphost ~/playbook$ vi inventory thor@jumphost ~/playbook$ cat inventory stapp01 ansible_host=172.16.238.10 ansible_ssh_pass=Ir0nM@n ansible_user=tony stapp02 ansible_host=172.16.238.11 ansible_ssh_pass=Am3ric@ ansible_user=steve stapp03 ansible_host=172.16.238.12 ansible_ssh_pass=BigGr33n ansible_user=banner thor@jumphost ~/playbook$ |
3. Create a playbook as per the task ( refer Video below for clarity )
thor@jumphost ~/playbook$vi playbook.yml thor@jumphost ~/playbook$ cat playbook.yml - name: Create file in appservers hosts: stapp01, stapp02, stapp03 become: yes tasks: - name: Create the file and set properties file: path: /opt/opt.txt owner: "{{ ansible_user }}" group: "{{ ansible_user }}" mode: "0755" state: touch thor@jumphost ~/playbook$ |
4.Post file saved , run below command to execute the playbook
thor@jumphost ~/playbook$ ansible-playbook -i inventory playbook.yml PLAY [Create file in appservers] ******************************************************************** TASK [Gathering Facts] ****************************************************************************** ok: [stapp03] ok: [stapp01] ok: [stapp02] TASK [Create the file and set properties] *********************************************************** changed: [stapp01] changed: [stapp02] changed: [stapp03] PLAY RECAP ****************************************************************************************** stapp01 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 stapp02 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 stapp03 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 thor@jumphost ~/playbook$ |
thor@jumphost ~/playbook$ ansible all -a "ls -lsd /opt/opt.txt" -i inventory stapp01 | CHANGED | rc=0 >> 0 -rwxr-xr-x 1 tony tony 0 Jul 12 10:54 /opt/opt.txt stapp03 | CHANGED | rc=0 >> 0 -rwxr-xr-x 1 banner banner 0 Jul 12 10:54 /opt/opt.txt stapp02 | CHANGED | rc=0 >> 0 -rwxr-xr-x 1 steve steve 0 Jul 12 10:54 /opt/opt.txt thor@jumphost ~/playbook$ |
Happy Learning!!!!
0 Comments