From ba4315158fcaaefe317a1ff6a8081b577417204f Mon Sep 17 00:00:00 2001 From: Donien <88634789+Donien@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:58:49 +0100 Subject: [PATCH] Add Director migration and kickstart handlers 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 --- roles/icingaweb2/handlers/main.yml | 11 +++++++++++ roles/icingaweb2/tasks/modules/director.yml | 15 +++------------ 2 files changed, 14 insertions(+), 12 deletions(-) create mode 100644 roles/icingaweb2/handlers/main.yml diff --git a/roles/icingaweb2/handlers/main.yml b/roles/icingaweb2/handlers/main.yml new file mode 100644 index 00000000..3dc19f69 --- /dev/null +++ b/roles/icingaweb2/handlers/main.yml @@ -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" diff --git a/roles/icingaweb2/tasks/modules/director.yml b/roles/icingaweb2/tasks/modules/director.yml index 640a38c1..7d02dcac 100644 --- a/roles/icingaweb2/tasks/modules/director.yml +++ b/roles/icingaweb2/tasks/modules/director.yml @@ -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'