Hello,
Recently, I have a problem about Ansible. In the current folder “test” contains a file “aaa.sh” with file mode “-rwxrwxr-x”. I copy the directory using the example playbook.
---
- name: Copy file
hosts: 192.168.8.22
remote_user: root
tasks:
- name: copy test
copy: src=./test dest=/work/
Then , I check this file in the hosts “192.168.8.22”. The file mode is “-rw-r–r–”.
Why the file mode was changed?
How to do rightly?
If you want to control the file permissions when placing a file, also be aware you have access to the “mode” parameter.
The source permissions on the local filesystem are not used.
If you are instead saying when replacing the file on the destination that the permissions change, let us know.
Hi, michael.
Thank you for your reply. But I still do not understand.
“The source permissions on the local filesystem are not used.”
When I copy some file on the local filesystem to remote locations, I may use this method like “copy: src=./test dest=/work/”.
But the problem is that there are many files with different permissions in a folder “./test”, each file separately set mode too much trouble.
Should we do it like the following example?
copy: src=./test/aa1.sh dest=/work/test/ mode=700
copy: src=./test/aa2.sh dest=/work/test/ mode=600
copy: src=./test/aa3.sh dest=/work/test/ mode=777
copy: src=./test/aa4.sh dest=/work/test/ mode=700
copy: src=./test/aa5.sh dest=/work/test/ mode=600
copy: src=./test/aa6.sh dest=/work/test/ mode=777
copy: src=./test/aa7.sh dest=/work/test/ mode=700
This should not be reasonable.
If you have specific requirements for each file, why not do this:
copy: src=“./test/{{ item.fname }}” dest=/work/test mode={{ item.fmode }}
with_items:
{ fname: ‘aa1.sh’, fmode: ‘0750’ }
{ fname: ‘aa2.txt’, fmode: ‘0644’ }
But I just want to specify the same file permissions for the local file and remote file.
I have dozens of GB files, hundreds of thousands of files.
sivel
(sivel)
August 29, 2014, 6:10pm
6
Perhaps you should instead look at the synchronize module instead of copy: http://docs.ansible.com/synchronize_module.html
May I try it. But some of the trouble to set the "rsync" server.
You didn’t say that you had hundred of thousands of files, you gave an example with 7 files. If you have many more than that, perhaps another method like the “synchronize” module would be better. Also, do you have to copy the files or can you NFS mount the directory to each machine?
Yes. I have to copy the files to each machine. I will try the “synchronize” method tomorrow. Thanks for the advice.