I've got an Ansible script which among many things copy's some files to the server:
- name: copy vhost basic files to folder
copy:
src: "{{ item }}"
dest: /var/www/vhosts/mmpew/
mode: 664
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
with_fileglob:
- ../files/vhost/*
Locally on my Macbook the files have the permissions -rw-r--r--
, but even though I set the mode in the ansible script to 664, the resulting files on the server have the permissions -r-----rwt
.
Why oh why do the resulting files on the server not match either the mode set in the ansible script, or the original permissions from my local filesystem from which they are copied?
I even tried to set the mode correctly using the Ansible file module:
- name: Make sure the files I just uploaded are chmodded correctly
file:
path: /var/www/vhosts/mmpew/{{ item }}
mode: 644
with_items:
- the.txt
- files.php
- here.py
but even though I get no errors from Ansible, the file modes are not set correctly.
Could anybody enlighten me as to what is wrong here? All tips are welcome!
If you want to copy a file from an Ansible Control Master to remote hosts, the COPY (scp) module would be just fine.
By default, the ansible copy module does a force copy to the destination and overwrites the existing file when present.
You can use the copy module to copy files and folders from the local server to the remote servers, between remote servers(only files), change the permission of the files, etc. You can use the fetch module to copy files from the remote machine to the local machine.
Use mode: 0644
The 0
is necessary.
You can specify the mode symbolically:
mode: u=rw,g=r,o=r
This is more readable and less error-prone. Symbolic mode is supported by Ansible >= 1.8, according to the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With