Ansible: How to chmod +x a file with Ansible?

ansible has mode parameter in file module exactly for this purpose.

To add execute permission for everyone (i.e. chmod a+x on command line):

- name: Changing perm of "/foo/bar.sh", adding "+x"
  file: dest=/foo/bar.sh mode=a+x

Symbolic modes are supported since version 1.8, on a prior version you need to use the octal bits.


The mode parameter should be specified when using the copy module.

Example:

- name: copy file and set permissions
  copy:
    src: script.sh
    dest: /directory/script.sh
    mode: a+x

You can change the permission of a file without copy module.

- name: Change permission on myScript.sh file
  file:
    path: /path/to/directory/myScript.sh
    state: file
    owner: root
    group: root
    mode: 0755