1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
{{% for path in FILEPATH %}}
{{% if IS_DIRECTORY %}}
{{%- if FILE_REGEX %}}
{{% set STATE="file" %}}
{{% set FIND_TYPE="-type f" %}}
{{% set FIND_FILE_REGEX="-regextype posix-extended -regex \"" ~ FILE_REGEX[loop.index0] ~ "\"" %}}
{{%- else %}}
{{% set STATE="directory" %}}
{{% set FIND_TYPE="-type d" %}}
{{% set FIND_FILE_REGEX="" %}}
{{%- endif %}}
{{%- if RECURSIVE %}}
{{% set FIND_RECURSE_ARGS="" %}}
{{%- else %}}
{{% set FIND_RECURSE_ARGS="-maxdepth 1" %}}
{{%- endif %}}
{{%- if ALLOW_STRICTER_PERMISSIONS %}}
{{% set PERMS="-perm /" + SEARCH_MODE %}}
{{%- else %}}
{{% set PERMS="\! -perm " + SEARCH_MODE %}}
{{%- endif %}}
{{%- if EXCLUDED_FILES %}}
{{% set EXCLUDED_FILES_ARGS="! -name \"" + EXCLUDED_FILES|join("\" ! -name \"") + "\"" %}}
{{%- else %}}
{{% set EXCLUDED_FILES_ARGS="" %}}
{{%- endif %}}
- name: Find {{{ path }}} file(s){{% if RECURSIVE %}} recursively{{% endif %}}
command: 'find -H {{{ path }}} {{{ FIND_RECURSE_ARGS }}} {{{ PERMS }}} {{{ EXCLUDED_FILES_ARGS }}} {{{ FIND_TYPE }}} {{{ FIND_FILE_REGEX }}}'
register: files_found
changed_when: False
failed_when: False
check_mode: no
- name: Set permissions for {{{ path }}} file(s)
file:
path: "{{ item }}"
mode: "{{{ FILEMODE }}}"
state: "{{{ STATE }}}"
with_items:
- "{{ files_found.stdout_lines }}"
{{% else %}}
- name: Test for existence {{{ path }}}
stat:
path: "{{{ path }}}"
register: file_exists
- name: Ensure permission {{{ FILEMODE }}} on {{{ path }}}
file:
path: "{{{ path }}}"
mode: "{{{ FILEMODE }}}"
when: file_exists.stat is defined and file_exists.stat.exists
{{% endif %}}
{{% endfor %}}
|