Resursively sync files and links to multiple users, preserving permissions, but not owner and group
I have a directory with several tools and text files that I would like to copy to multiple users homedirs on given host. There are couple of caveats:
- I don't want to list the files in playbook
- Some files are executable, some are not
- I want the files to be owned by their respective users
- I want the symlinks to be copied as-is
When pushing to ansible_user
home dir, there's no issue as ansible.posix.synchronize
does the job very well with archive=true
and owner
/group
set to false
:
- name: Sync testing_files repo to ansible_user
ansible.posix.synchronize:
src: ~/testing_files/
dest: ~/testing_files/
mode: push
archive: true
delete: true
owner: false
group: false
register: rsync_output
The links are properly handled as well (they are rsynced as symlinks).
However, the problem is with populating the same for other users. I tried the following approach:
- name: Sync testing_files repo to extra_users
ansible.builtin.copy:
src: ~/testing_files/
dest: ~/testing_files/
remote_src: true
mode: preserve
owner: ""
follow: true # I tried with `false` as well
with_items:
- ""
The file permissions are correct, the owner as well, however:
- the group of file remains the same as source file
- the symlinks are ignored
How can I make it work? For the group issue the only solution I came up is to have another task that will run stat
to check group and save it for future use, e.g. like this:
- name: Get group of homedir
ansible.builtin.stat:
path: "~"
register: homedir
with_items:
- ""
- name: Sync testing_files repo to extra_users
ansible.builtin.copy:
src: ~/testing_files/
dest: "~/testing_files/"
remote_src: true
mode: preserve
owner: ""
group: "Liquid error: wrong number of arguments (given 1, expected 2)"
follow: true
with_items:
- ""
(NOTE: extra_users_or_empty: ""
)
However that feels like something that should be achieved in more elegant way. And for symlinks - I have no idea why the ansible.builtin.copy
ignores them.
Any ideas?
from Recent Questions - Stack Overflow https://ift.tt/dAH0Mxn
https://ift.tt/CuxWqsp
Comments
Post a Comment