File: ansible.template

package info (click to toggle)
scap-security-guide 0.1.65-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 71,936 kB
  • sloc: xml: 179,374; sh: 69,771; python: 23,819; makefile: 23
file content (64 lines) | stat: -rw-r--r-- 1,516 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
59
60
61
62
63
64
# 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 %}}

{{%- if ALLOW_STRICTER_PERMISSIONS %}}
{{% set PERMS="-perm /" + SEARCH_MODE %}}
{{%- else %}}
{{% set PERMS="\! -perm " + SEARCH_MODE %}}
{{%- endif %}}

- name: Find {{{ path }}} file(s){{% if RECURSIVE %}} recursively{{% endif %}}
  command: 'find -H {{{ path }}} {{{ FIND_RECURSE_ARGS }}} {{{ PERMS }}} -type f -regex "{{{ FILE_REGEX[loop.index0] }}}"'
  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: file
  with_items:
    - "{{ files_found.stdout_lines }}"

{{% else %}}

- name: Set permissions for {{{ path }}}{{% if RECURSIVE %}} recursively{{% endif %}}
  file:
    path: "{{{ path }}}"
    state: directory
{{% if RECURSIVE %}}
    recurse: yes
{{% endif %}}
    mode: "{{{ FILEMODE }}}"

{{% endif %}}
{{% 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 %}}