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