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
|
# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low
{{%- for path in FILEPATH %}}
{{%- if IS_DIRECTORY %}}
{{%- if FILE_REGEX %}}
{{%- if RECURSIVE %}}
{{%- set FIND_RECURSE_ARGS="" %}}
{{%- else %}}
{{%- set FIND_RECURSE_ARGS="-maxdepth 1" %}}
{{%- endif %}}
- name: Find {{{ path }}} file(s) matching {{{ FILE_REGEX[loop.index0] }}}{{% if RECURSIVE %}} recursively{{% endif %}}
command: 'find -H {{{ path }}} {{{ FIND_RECURSE_ARGS }}} -type f ! -group {{{ GID_OR_NAME }}} -regextype posix-extended -regex "{{{ FILE_REGEX[loop.index0] }}}"'
register: files_found
changed_when: False
failed_when: False
check_mode: no
- name: Ensure group owner on {{{ path }}} file(s) matching {{{ FILE_REGEX[loop.index0] }}}
file:
path: "{{ item }}"
group: "{{{ GID_OR_NAME }}}"
state: file
with_items:
- "{{ files_found.stdout_lines }}"
{{% else %}}
- name: Ensure group owner on {{{ path }}}{{% if RECURSIVE %}} recursively{{% endif %}}
file:
path: "{{{ path }}}"
state: directory
{{% if RECURSIVE %}}
recurse: yes
{{% endif %}}
group: "{{{ GID_OR_NAME }}}"
{{% endif %}}
{{% else %}}
- name: Test for existence {{{ path }}}
stat:
path: "{{{ path }}}"
register: file_exists
- name: Ensure group owner {{{ GID_OR_NAME }}} on {{{ path }}}
file:
path: "{{{ path }}}"
group: "{{{ GID_OR_NAME }}}"
when: file_exists.stat is defined and file_exists.stat.exists
{{% endif %}}
{{% endfor %}}
|