# platform = multi_platform_all
# reboot = false
# strategy = configure
# complexity = low
# disruption = low

{{% if IS_DIRECTORY and FILE_REGEX %}}

- name: Find {{{ FILEPATH }}} file(s) matching {{{ FILE_REGEX }}}
  find:
    paths: "{{{ FILEPATH }}}"
    patterns: "{{{ FILE_REGEX }}}"
    use_regex: yes
  register: files_found

- name: Ensure group owner on {{{ FILEPATH }}} file(s) matching {{{ FILE_REGEX }}}
  file:
    path: "{{ item.path }}"
    owner: "{{{ FILEUID }}}"
  with_items:
    - "{{ files_found.files }}"

{{% else %}}

- name: Test for existence {{{ FILEPATH }}}
  stat:
    path: "{{{ FILEPATH }}}"
  register: file_exists

- name: Ensure owner {{{ FILEUID }}} on {{{ FILEPATH }}}
  file:
    path: "{{{ FILEPATH }}}"
    owner: "{{{ FILEUID }}}"
  when: file_exists.stat is defined and file_exists.stat.exists

{{% endif %}}
