Skip to content

Commit d9156b5

Browse files
jensrudolfJens Rudolf
andauthored
Add action_group to enable module default groups (#175)
* Add action_group to enable module default groups This is to support a feature provided by ansible-core >= 2.12 that enables providing default values for a group of modules instead of each module seperately. See https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html#module-defaults-groups for more details. * Add integration test for module group defaults * Document usage of module defaults groups * Run defaults_test only on ansible-core >= 2.12 Co-authored-by: Jens Rudolf <jens.rudolf@aida.de>
1 parent f8940b6 commit d9156b5

5 files changed

Lines changed: 91 additions & 1 deletion

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ jobs:
154154
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
155155

156156
- name: Run integration tests
157-
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
157+
run: ansible-test integration --exclude defaults_test -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
158+
159+
- name: Run integration tests for defaults module on ansible 2.12 and above
160+
run: ansible-test integration defaults_test -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --requirements --coverage
161+
if: (matrix.ansible != 'stable-2.9') && (matrix.ansible != 'stable-2.10') && (matrix.ansible != 'stable-2.11')
158162

159163
# ansible-test support producing code coverage date
160164
- name: Generate coverage report

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ Then you can use the dynamic inventory like this:
133133
ansible-playbook -i inventory.icinga_director_inventory.yaml path/to/your/playbook.yml
134134
```
135135

136+
## Example using module defaults groups
137+
138+
With ansible-core >= 2.12 it is possible to specify defaults paramters for all modules in this collection using [Module defaults groups](https://docs.ansible.com/ansible/latest/user_guide/playbooks_module_defaults.html#module-defaults-groups). Use it like this:
139+
140+
```
141+
- hosts: localhost
142+
143+
module_defaults:
144+
group/t_systems_mms.icinga_director.icinga:
145+
url: "https://example.com"
146+
url_username: foo
147+
url_password: bar
148+
149+
tasks:
150+
- name: Create host
151+
t_systems_mms.icinga_director.icinga_host:
152+
object_name: myhost
153+
address: 172.0.0.1
154+
155+
- name: Create command
156+
t_systems_mms.icinga_director.icinga_command:
157+
object_name: my-command
158+
command: my-command.sh
159+
```
160+
136161
## Contributing
137162

138163
See [Contributing](CONTRIBUTING.md).

meta/runtime.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,43 @@
11
---
22
requires_ansible: '>=2.9.10'
3+
4+
action_groups:
5+
icinga:
6+
- icinga_command
7+
- icinga_command_info
8+
- icinga_command_template
9+
- icinga_command_template_info
10+
- icinga_endpoint
11+
- icinga_endpoint_info
12+
- icinga_host
13+
- icinga_host_info
14+
- icinga_host_template
15+
- icinga_host_template_info
16+
- icinga_hostgroup
17+
- icinga_hostgroup_info
18+
- icinga_notification
19+
- icinga_notification_info
20+
- icinga_notification_template
21+
- icinga_notification_template_info
22+
- icinga_scheduled_downtime
23+
- icinga_service
24+
- icinga_service_apply
25+
- icinga_service_apply_info
26+
- icinga_service_info
27+
- icinga_service_template
28+
- icinga_service_template_info
29+
- icinga_servicegroup
30+
- icinga_servicegroup_info
31+
- icinga_serviceset
32+
- icinga_timeperiod
33+
- icinga_timeperiod_info
34+
- icinga_timeperiod_template
35+
- icinga_timeperiod_template_info
36+
- icinga_user
37+
- icinga_user_group
38+
- icinga_user_group_info
39+
- icinga_user_info
40+
- icinga_user_template
41+
- icinga_user_template_info
42+
- icinga_zone
43+
- icinga_zone_info
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: provide module defaults
3+
hosts: localhost
4+
module_defaults:
5+
group/t_systems_mms.icinga_director.icinga:
6+
url: "http://127.0.0.1/icingaweb2"
7+
url_username: "icingaadmin"
8+
url_password: "icinga"
9+
tasks:
10+
- name: Create command
11+
t_systems_mms.icinga_director.icinga_command:
12+
state: present
13+
command: "true"
14+
command_type: "PluginCheck"
15+
object_name: defaults_test
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
5+
ansible-playbook defaults_test.yml -v --diff

0 commit comments

Comments
 (0)