kramer65
kramer65

Reputation: 53933

Ansible copy doesn't set file mode correctly

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!

Upvotes: 7

Views: 4716

Answers (3)

Z.Liu
Z.Liu

Reputation: 423

there are two kinds of method to define the mode

first:

mode: 0644

second:

mode: '644'

Upvotes: 0

René Pijl
René Pijl

Reputation: 4738

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.

Upvotes: 6

Jack
Jack

Reputation: 6168

Use mode: 0644

The 0 is necessary.

Upvotes: 10

Related Questions