Hi All,
I am trying to create a file in /opt folder. My playbook(from test role) looks like,
- name: create file
file:
path: /opt/testfile
state: touch
And main.yml looks like,
- hosts: ‘{{ host }}’
become: yes
become_method: sudo
become_user: jenkins
roles:- test
I am running the playbook as,
ansible-playbook -i /tmp/ansible-workspace/environments/QA/inventory --extra-vars “host=QA” --ask-pass --ask-become-pass main.yml -vvv
And the error I get is,
“mode”: “0644”,
“msg”: “Error while touching existing target: [Errno 13] Permission denied: ‘/opt/testfile’”,
“owner”: “root”,
“path”: “/opt/testfile”,
“secontext”: “unconfined_u:object_r:etc_t:s0”,
“size”: 0,
“state”: “file”,
“uid”: 0
But when I comment out the line become_user: jenkins in main.yml and run it with the command
ansible-playbook -i /tmp/ansible-workspace/environments/QA/inventory --extra-vars “host=QA” -u jenkins --ask-pass --ask-become-pass main.yml -vvv
it works perfectly fine.
Can someone please say teh differnce between the two ways?
Thanks