Skip to content

Commit 24fa1c0

Browse files
authored
Correctly create 'roles.ini' (#416)
`roles.ini` is now created correctly even if `icingaweb2_admin_username` is not defined. `icingaweb2_roles` can now be used without the need for an initial admin user.
1 parent ac7e05d commit 24fa1c0

File tree

3 files changed

+64
-69
lines changed

3 files changed

+64
-69
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bugfixes:
2+
- :code:`icingaweb2_roles` was not deployed at all if :code:`icingaweb2_admin_username` and :code:`icingaweb2_admin_password` were missing.
3+
Now for both, the predefined admin role and user-defined :code:`icingaweb2_roles`, the respective variables are tested for correctly when creating :code:`roles.ini`.
4+
Thus, the creation of an initial admin user is no longer strictly necessary.
5+
- A short example for the previously undocumented :code:`icingaweb2_roles` has been added.

doc/role-icingaweb2/role-icingaweb2.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,24 @@ icingaweb2_groups:
144144
```
145145

146146
For more information about key value pairs for different authentication methods see the [official documentation](https://icinga.com/docs/icinga-web/latest/doc/05-Authentication/).
147+
148+
### Roles
149+
150+
Icinga Web 2 roles can be created using `icingaweb2_roles`. Options for roles need to be set in accordance with the [upstream documentation](https://icinga.com/docs/icinga-web/latest/doc/06-Security/#roles). Depending on the installed modules other options might be available.
151+
152+
```
153+
icingaweb2_roles:
154+
watchers:
155+
users:
156+
- "some-user"
157+
- "another-user"
158+
groups:
159+
- "some-group"
160+
- "another-group"
161+
permissions:
162+
- "module/icingadb"
163+
- "icingadb/command/downtime/*"
164+
refusals:
165+
- "icingadb/object/show-source"
166+
icingadb/filter/hosts: "host.name=*windows*"
167+
```

roles/icingaweb2/tasks/manage_icingaweb_config.yml

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,24 @@
3939
dest: "{{ icingaweb2_config_dir }}/{{ item }}.ini"
4040
owner: "{{ icingaweb2_httpd_user }}"
4141
group: "{{ icingaweb2_group }}"
42-
mode: "0770"
42+
mode: "0660"
4343
loop:
4444
- config
4545
- authentication
4646
- groups
4747
vars:
4848
_i2_config_hash: "{{ lookup('ansible.builtin.vars', 'icingaweb2_' + item) }}"
4949

50-
- name: Prepare config hash
50+
- name: Create temporary config variable
5151
ansible.builtin.set_fact:
52-
_i2_config_hash:
52+
_tmp_i2_config_hash:
53+
roles: {}
54+
resources: {}
55+
56+
- name: Prepare config hash
57+
when: icingaweb2_db is defined
58+
vars:
59+
_resources:
5360
icingaweb2_db:
5461
type: db
5562
db: "{{ icingaweb2_db['type'] | default('mysql') }}"
@@ -65,76 +72,38 @@
6572
ssl_ca: "{{ icingaweb2_db['ssl_ca'] | default(omit) }}"
6673
ssl_cipher: "{{ icingaweb2_db['ssl_cipher'] | default(omit) }}"
6774
ssl_capath: "{{ icingaweb2_db['ssl_capath'] | default(omit) }}"
68-
when: icingaweb2_db is defined
69-
70-
- name: Assemble resources.ini
71-
when: icingaweb2_db is defined or icingaweb2_resources is defined
72-
block:
73-
- name: Manage icingaweb_db resource config
74-
ansible.builtin.template:
75-
src: modules_config.ini.j2
76-
dest: "{{ icingaweb2_fragments_path }}/resources/resources_01"
77-
owner: root
78-
group: "{{ icingaweb2_group }}"
79-
when: icingaweb2_db is defined
80-
81-
- name: Set resources facts
82-
ansible.builtin.set_fact:
83-
_i2_config_hash: "{{ icingaweb2_resources }}"
84-
when: icingaweb2_resources is defined
75+
ansible.builtin.set_fact:
76+
_tmp_i2_config_hash: "{{ _tmp_i2_config_hash | combine({'resources': _resources}, recursive=true) }}"
8577

86-
- name: Manage Resources
87-
ansible.builtin.template:
88-
src: modules_config.ini.j2
89-
dest: "{{ icingaweb2_fragments_path }}/resources/resources_02"
90-
owner: root
91-
group: "{{ icingaweb2_group }}"
92-
when: icingaweb2_resources is defined
78+
- name: Set resources facts
79+
when: icingaweb2_resources is defined
80+
ansible.builtin.set_fact:
81+
_tmp_i2_config_hash: "{{ _tmp_i2_config_hash | combine({'resources': icingaweb2_resources}, recursive=true) }}"
9382

94-
- name: Assemble roles.ini
83+
- name: Assemble roles.ini (adding default admin role)
9584
when: icingaweb2_admin_username is defined and icingaweb2_admin_password is defined
96-
block:
97-
- name: Build variable
98-
ansible.builtin.set_fact:
99-
_i2_config_hash:
100-
default_admins:
101-
users:
102-
- "{{ icingaweb2_admin_username }}"
103-
permissions:
104-
- "*"
105-
106-
- name: Manage icingaweb2_admin privileges
107-
ansible.builtin.template:
108-
src: modules_config.ini.j2
109-
dest: "{{ icingaweb2_fragments_path }}/roles/roles_01"
110-
owner: root
111-
group: "{{ icingaweb2_group }}"
112-
when: icingaweb2_admin_username is defined and icingaweb2_admin_password is defined
113-
114-
- name: Build variable
115-
ansible.builtin.set_fact:
116-
_i2_config_hash: "{{ icingaweb2_roles }}"
117-
when: icingaweb2_roles is defined
118-
119-
- name: Manage icingaweb2_admin privileges
120-
ansible.builtin.template:
121-
src: modules_config.ini.j2
122-
dest: "{{ icingaweb2_fragments_path }}/roles/roles_02"
123-
owner: root
124-
group: "{{ icingaweb2_group }}"
125-
when: icingaweb2_roles is defined
85+
vars:
86+
_tmp_i2_config_hash_admin_role:
87+
default_admins:
88+
users:
89+
- "{{ icingaweb2_admin_username }}"
90+
permissions:
91+
- "*"
92+
ansible.builtin.set_fact:
93+
_tmp_i2_config_hash: "{{ _tmp_i2_config_hash | combine({'roles': _tmp_i2_config_hash_admin_role}, recursive=true) }}"
12694

95+
- name: Assemble roles.ini (adding icingaweb2_roles)
96+
when: icingaweb2_roles is defined
97+
ansible.builtin.set_fact:
98+
_tmp_i2_config_hash: "{{ _tmp_i2_config_hash | combine({'roles': icingaweb2_roles}, recursive=true) }}"
12799

128-
- name: Assemble configuration files
129-
ansible.builtin.assemble:
130-
dest: "{{ icingaweb2_config_dir }}/{{ item }}.ini"
131-
src: "{{ icingaweb2_fragments_path }}/{{ item }}"
100+
- name: Deploy configuration files
101+
loop: "{{ _tmp_i2_config_hash | dict2items }}"
102+
vars:
103+
_i2_config_hash: "{{ _tmp_i2_config_hash[item.key] }}"
104+
ansible.builtin.template:
105+
src: modules_config.ini.j2
106+
dest: "{{ icingaweb2_config_dir }}/{{ item.key }}.ini"
132107
group: "{{ icingaweb2_group }}"
133108
owner: "{{ icingaweb2_httpd_user }}"
134-
mode: 0770
135-
loop:
136-
- resources
137-
- roles
138-
139-
140-
# {{ icingaweb2_db | ansible.builtin.combine(icingaweb2_db, append_rp)}}
109+
mode: "0660"

0 commit comments

Comments
 (0)