使用ansible基于文件扩展名的权限更改

Permission change based on file extension using ansible

我想使用 ansible 根据它的扩展名更改文件的权限,例如我有目录 test 并且在这个目录中我有很多 shell 脚本(.sh)和 python(.py) 文件。我想将 shell 脚本的权限更改为 0700,将 python 文件的权限更改为 0644。你能帮我看看我该如何实现吗?谢谢

有很多方法可以做到这一点。这应该工作。根据您的需要进行调整。

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

如果文件在远程,执行此操作:

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

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