Skip to content

Commit

Permalink
Add Director migration and kickstart handlers
Browse files Browse the repository at this point in the history
This adds handlers to the 'icingaweb2' role to take care of Icinga
Director schema migrations and its kickstart. Running multiple roles in
order should also run their handlers in order. This way the Icinga 2 API
should be up and operational for the Director to use for kickstart.

Fixes #319
  • Loading branch information
Donien committed Oct 31, 2024
1 parent 3ed3687 commit ba43151
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 11 additions & 0 deletions roles/icingaweb2/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---

- name: Module Director | Apply pending migrations
ansible.builtin.command:
cmd: icingacli director migration run
listen: "run_director_migrations"

- name: Module Director | Run kickstart if required
ansible.builtin.command:
cmd: icingacli director kickstart run
listen: "run_director_kickstart"
15 changes: 3 additions & 12 deletions roles/icingaweb2/tasks/modules/director.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,16 @@
register: _pending
changed_when: _pending.rc|int == 0
failed_when: _pending.stdout|length > 0
when: icingaweb2_modules['director']['import_schema'] is defined and icingaweb2_modules.director.import_schema and icingaweb2_modules['director']['config'] is defined

- name: Module Director | Apply pending migrations # noqa: command-instead-of-shell
ansible.builtin.shell:
cmd: icingacli director migration run
when: icingaweb2_modules['director']['import_schema'] is defined and icingaweb2_modules.director.import_schema and icingaweb2_modules['director']['config'] is defined and _pending.rc|int == 0
notify: "run_director_migrations"

- name: Module Director | Check if kickstart is required # noqa: command-instead-of-shell
ansible.builtin.shell:
cmd: icingacli director kickstart required
register: _required
changed_when: _required.rc|int == 0
changed_when: (_required.rc|int == 0) or (".icinga_host' doesn't exist" in _required.stderr)
failed_when: _required.rc|int >= 2
when: icingaweb2_modules['director']['run_kickstart'] is defined and icingaweb2_modules.director.run_kickstart and icingaweb2_modules['director']['kickstart'] is defined

- name: Module Director | Run kickstart if required # noqa: command-instead-of-shell
ansible.builtin.shell:
cmd: icingacli director kickstart run
when: icingaweb2_modules['director']['run_kickstart'] is defined and icingaweb2_modules.director.run_kickstart and icingaweb2_modules['director']['kickstart'] is defined and _required.rc|int == 0
notify: "run_director_kickstart"

- name: Module Director | Ensure installation from source is complete
when: icingaweb2_modules['director']['source'] == 'git'
Expand Down

0 comments on commit ba43151

Please sign in to comment.