Question : 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 /home/web.txt on all app servers.
c. The /home/web.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.
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.
3. Create a playbook as per the task ( refer Video below for clarity )
- name: Create file in appservers
hosts: stapp01, stapp02, stapp03
become: yes
tasks:
- name: Create the file and set properties
file:
path: /home/web.txt
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0755"
state: touch
4.Post file saved , run below command to execute the playbook
Happy Learning!!!!
2 Comments
Hi,
ReplyDeleteWhat's the purpose of "become: yes"? referring to https://docs.ansible.com/ansible/2.3/become.html, "become
set to ‘true’/’yes’ to activate privilege escalation".
So my understanding it acts as 'root', is it correct? if YES then why doesn't specify "become_user is root"?
Thanks!
Thanks for comment DANNIE TJ.. no its not like root.
Deletebecome
set to yes to activate privilege escalation.
become_user
set to user with desired privileges — the user you become, NOT the user you login as. Does NOT imply become: yes, to allow it to be set at host level. Default value is root.
for further reference you can have ansible doc