File: ansible.template

package info (click to toggle)
scap-security-guide 0.1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 110,644 kB
  • sloc: xml: 241,883; sh: 73,777; python: 32,527; makefile: 27
file content (58 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download
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 ! -uid {{{ FILEUID }}} -regextype posix-extended -regex "{{{ FILE_REGEX[loop.index0] }}}"'
  register: files_found
  changed_when: False
  failed_when: False
  check_mode: no

- name: Ensure owner on {{{ path }}} file(s) matching {{{ FILE_REGEX[loop.index0] }}}
  file:
    path: "{{ item }}"
    owner: "{{{ FILEUID }}}"
    state: file
  with_items:
    - "{{ files_found.stdout_lines }}"

{{% else %}}

- name: Ensure owner on directory {{{ path }}}{{% if RECURSIVE %}} recursively{{% endif %}}
  file:
    path: "{{{ path }}}"
    state: directory
{{% if RECURSIVE %}}
    recurse: yes
{{% endif %}}
    owner: "{{{ FILEUID }}}"

{{% endif %}}
{{% else %}}

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

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

{{% endif %}}
{{% endfor %}}