why the mode of files was changed when copy the file to remote computer.

72 views
Skip to first unread message

Simon Zhang

unread,
Aug 29, 2014, 6:03:13 AM8/29/14
to ansible...@googlegroups.com
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?



Michael DeHaan

unread,
Aug 29, 2014, 8:00:02 AM8/29/14
to ansible...@googlegroups.com
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.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9376eb7a-67da-4233-9488-3f05fd598eb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Simon Zhang

unread,
Aug 29, 2014, 12:43:00 PM8/29/14
to ansible...@googlegroups.com
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.

Mark McCoy

unread,
Aug 29, 2014, 1:31:48 PM8/29/14
to ansible-project
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' }

 

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

Simon Zhang

unread,
Aug 29, 2014, 2:07:02 PM8/29/14
to ansible...@googlegroups.com
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.


Matt Martz

unread,
Aug 29, 2014, 2:11:41 PM8/29/14
to ansible...@googlegroups.com
Perhaps you should instead look at the synchronize module instead of copy:  http://docs.ansible.com/synchronize_module.html



For more options, visit https://groups.google.com/d/optout.

Simon Zhang

unread,
Aug 29, 2014, 3:13:03 PM8/29/14
to ansible...@googlegroups.com
2014-08-30 2:10 GMT+08:00 Matt Martz <ma...@sivel.net>:
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.
 

Mark McCoy

unread,
Aug 29, 2014, 3:13:36 PM8/29/14
to ansible-project
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?
On Fri, Aug 29, 2014 at 1:06 PM, Simon Zhang <hap...@gmail.com> wrote:

Simon Zhang

unread,
Aug 29, 2014, 3:20:48 PM8/29/14
to ansible...@googlegroups.com
Yes. I have to copy the files to each machine. I will try the "synchronize" method tomorrow. Thanks for the advice.


Reply all
Reply to author
Forward
0 new messages