file changes ownership when edited from another user Ansible

Viewed 34

copy_playbook.yml

- name: copy file from ansible to serverB
  hosts: serverB
  task:

#logged in as user1 

  - name: editing user2 file 

    copy:

      src: /etc/Ansible/aText.txt

      dest: /home/user2/aText_ansible.txt

      owner: user2

      group: user2

      backup: yes

host/inventory

[serverB]
serverB.example.com
[serverB:vars]
ansible_ssh_user=user1

When the file is changed the owner becomes user1.

How would I keep the owner the same without logging in as root or editing the sudoer file to allow user1 to log into user2.

0 Answers
Related