File tree Expand file tree Collapse file tree 7 files changed +68
-4
lines changed
Expand file tree Collapse file tree 7 files changed +68
-4
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,12 @@ This example is taken from [`molecule/default/converge.yml`](https://github.com/
9292 - name : example-prerotate
9393 path : " /var/log/example-prerotate/*.log"
9494 prerotate : touch /tmp/logrotate-prerotate
95+ - name : example-paths
96+ paths :
97+ - " /var/log/example-paths/a.log"
98+ - " /var/log/example-paths/b.log"
99+ frequency : weekly
100+ keep : 4
95101 - name : example-absent
96102 state : absent
97103 # Negative numbers work on some distributions: `error: example-negative:10 bad rotation count '-1'\`
@@ -135,6 +141,7 @@ The machine needs to be prepared. In CI this is done using [`molecule/default/pr
135141 - /var/log/example-dateyesterday
136142 - /var/log/example-prerotate
137143 - /var/log/example-su
144+ - /var/log/example-paths
138145
139146 - name: Create log file
140147 ansible.builtin.copy:
@@ -154,6 +161,8 @@ The machine needs to be prepared. In CI this is done using [`molecule/default/pr
154161 - /var/log/example-dateyesterday/app.log
155162 - /var/log/example-prerotate/app.log
156163 - /var/log/example-su/app.log
164+ - /var/log/example-paths/a.log
165+ - /var/log/example-paths/b.log
157166 - /var/log/btmp
158167 - /var/log/wtmp
159168 - /var/log/hawkey.log
Original file line number Diff line number Diff line change @@ -48,3 +48,18 @@ argument_specs:
4848 type : bool
4949 description : " Set the enabled state the service."
5050 default : true
51+ logrotate_entries :
52+ type : list
53+ elements : dict
54+ description : " List of logrotate.d entries. Each entry must have either path (single path) or paths (list of paths), mutually exclusive."
55+ suboptions :
56+ name :
57+ type : str
58+ description : " Name of the config file in logrotate.d."
59+ path :
60+ type : str
61+ description : " Single log path. Mutually exclusive with paths."
62+ paths :
63+ type : list
64+ elements : str
65+ description : " Multiple log paths for one block. Mutually exclusive with path."
Original file line number Diff line number Diff line change 7979 - name : example-prerotate
8080 path : " /var/log/example-prerotate/*.log"
8181 prerotate : touch /tmp/logrotate-prerotate
82+ - name : example-paths
83+ paths :
84+ - " /var/log/example-paths/a.log"
85+ - " /var/log/example-paths/b.log"
86+ frequency : weekly
87+ keep : 4
8288 - name : example-absent
8389 state : absent
8490 # Negative numbers work on some distributions: `error: example-negative:10 bad rotation count '-1'\`
Original file line number Diff line number Diff line change 2727 - /var/log/example-dateyesterday
2828 - /var/log/example-prerotate
2929 - /var/log/example-su
30+ - /var/log/example-paths
3031
3132 - name : Create log file
3233 ansible.builtin.copy :
4647 - /var/log/example-dateyesterday/app.log
4748 - /var/log/example-prerotate/app.log
4849 - /var/log/example-su/app.log
50+ - /var/log/example-paths/a.log
51+ - /var/log/example-paths/b.log
4952 - /var/log/btmp
5053 - /var/log/wtmp
5154 - /var/log/hawkey.log
Original file line number Diff line number Diff line change 2020 - logrotate_prerotate_marker.stat.exists
2121 - logrotate_prerotate_marker.stat.isreg
2222 quiet : true
23+
24+ - name : Read example-paths logrotate config
25+ ansible.builtin.slurp :
26+ src : /etc/logrotate.d/example-paths
27+ register : example_paths_config
28+
29+ - name : Assert example-paths config contains both paths and shared block
30+ ansible.builtin.assert :
31+ that :
32+ - (example_paths_config.content | b64decode) is search("/var/log/example-paths/a.log")
33+ - (example_paths_config.content | b64decode) is search("/var/log/example-paths/b.log")
34+ - (example_paths_config.content | b64decode) is search("weekly")
35+ - (example_paths_config.content | b64decode) is search("rotate 4")
36+ quiet : true
Original file line number Diff line number Diff line change 6565 - item.name is defined
6666 - item.name is string
6767 - item.name is not none
68- - item.path is defined
69- - item.path is string
70- - item.path is not none
68+ - >
69+ (item.path is defined and item.path is string and item.path is not none
70+ and item.paths is not defined)
71+ or
72+ (item.paths is defined and item.paths is iterable and item.paths is not string
73+ and item.paths is not mapping and item.path is not defined)
7174 quiet : true
7275 loop : " {{ logrotate_entries }}"
7376 loop_control :
7679 - logrotate_entries is defined
7780 - item.state is not defined or item.state != "absent"
7881
82+ - name : assert | Test paths in logrotate_entries (each path is string)
83+ ansible.builtin.assert :
84+ that :
85+ - (item.paths | reject("string") | list | length) == 0
86+ - (item.paths | select("none") | list | length) == 0
87+ quiet : true
88+ loop : " {{ logrotate_entries }}"
89+ loop_control :
90+ label : " {{ item.name }}"
91+ when :
92+ - logrotate_entries is defined
93+ - item.state is not defined or item.state != "absent"
94+ - item.paths is defined
95+
7996- name : assert | Test state in logrotate_entries
8097 ansible.builtin.assert :
8198 that :
Original file line number Diff line number Diff line change 11{{ ansible_managed | comment }}
22
3- {{ item.path }} {
3+ {% if item . paths is defined %} {{ item.paths | join(' ') }} {% else %} {{ item. path }} {% endif %} {
44
55{% if item .frequency is defined %} {{ item.frequency }}
66{% endif -%}{% if item .compress is defined and item .compress %} compress
You can’t perform that action at this time.
0 commit comments