Arbab Nazar
Arbab Nazar

Reputation: 23801

Permission change based on file extension using ansible

I want to change the permission of the file based on it's extension using ansible, for example I have directory test and within this directory I have a lot of shell script(.sh) and python(.py) files. I want to change the permission of shell script to 0700 and python files to 0644. Can you please help me that how I can achieve this. Thanks

Upvotes: 1

Views: 1467

Answers (1)

helloV
helloV

Reputation: 52423

There are many ways to do this. This should work. Tweak it to your needs.

  - file: path={{item}} mode=0644
    with_fileglob:
        - <full_path>/*.py
  - file: path={{item}} mode=0700
    with_fileglob:
        - <full_path>/*.sh

If the files are on remote, do this:

  - shell: ls /test/*.py
    register: py_files

  - file: path={{item}} mode=0644
    with_items: py_files.stdout_lines

Upvotes: 3

Related Questions