Here, in this code, I’m trying to change the ownership from root:root to user:user. It is failing to do so!
Due to this ownership issue, it is giving error at next step.
Logs of error:
TASK [Change ownership of output_dir directory to "user"] **********************************************************************************************
changed: [ip]
TASK [Download Output File Locally] ************************************************************************************************************************
fatal: [ip]: FAILED! => {"msg": "Unable to create local directories(/tmp/log/dir1/dir2): [Errno 13] Permission denied: b'/tmp/log/dir1/dir2'"}
This code is not even giving any error.
- my code!
hosts: "{{ profile }}"
remote_user: "{{ user }}"
vars:
code_name: xenial
user: "{{ user }}"
output_dir: "{{ output_dir }}"
tasks:
- name: Create Template OS Version file
shell: echo "" > /home/{{ user }}/os-version.txt
- name: Run the shell command to get raw OS data
shell: |
cat /etc/*release > os-version.txt
- name: Change ownership of output_dir directory to "user"
file:
path: "{{ output_dir }}"
owner: "{{ new_owner }}"
state: directory
become: yes
- name: Download Output File Locally
fetch:
src: /home/{{ user }}/os-version.txt
dest: "{{ output_dir }}os-version.txt"
flat: yes
become: yes
become_user: root
- name: Clean up footprints
shell: |
rm /home/{{ user }}/os-version.txt