From 902e638d956c858808d9084469b728df359385ec Mon Sep 17 00:00:00 2001 From: Logan V Date: Sat, 16 Sep 2017 14:23:03 -0500 Subject: [PATCH] Add external LB management handler hook interface Based on conversation on an ansible issue[1], I implemented a LB orchestration role[2] similar to the POC here[3]. This will allow external loadbalancer management roles to hook into a universal notify listener "Manage LB" to perform before/ after endpoint management actions when the service is being restarted. [1]: https://github.com/ansible/ansible/issues/27813 [2]: https://github.com/Logan2211/ansible-haproxy-endpoints [3]: https://github.com/Logan2211/tmp-ansible-27813 Change-Id: I5aecc26606f41bc6b27fbe9a5f600914a88ff2c7 --- doc/source/index.rst | 13 +++++++++++++ handlers/main.yml | 4 ++++ tasks/consoles/nova_console_novnc_ssl.yml | 4 +++- tasks/nova_init_systemd.yml | 2 ++ tasks/nova_install.yml | 8 ++++++-- tasks/nova_post_install.yml | 8 ++++++-- tasks/nova_uwsgi.yml | 1 + 7 files changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 210ff805..29cf26c7 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -31,6 +31,19 @@ Example playbook .. literalinclude:: ../../examples/playbook.yml :language: yaml +External Restart Hooks +~~~~~~~~~~~~~~~~~~~~~~ + +When the role performs a restart of the service, it will notify an Ansible +handler named ``Manage LB``, which is a noop within this role. In the +playbook, other roles may be loaded before and after this role which will +implement Ansible handler listeners for ``Manage LB``, allowing external roles +to manage the load balancer endpoints responsible for sending traffic to the +servers being restarted by marking them in maintenance or active mode, +draining sessions, etc. For an example implementation, please reference the +`ansible-haproxy-endpoints role `_ +used by the openstack-ansible project. + Tags ~~~~ diff --git a/handlers/main.yml b/handlers/main.yml index 9b4bd038..2b81ca57 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -74,3 +74,7 @@ - "'nova_compute' in group_names" - "nova_discover_hosts_in_cells_interval | int < 1" listen: "Restart nova services" + +- meta: noop + listen: Manage LB + when: false diff --git a/tasks/consoles/nova_console_novnc_ssl.yml b/tasks/consoles/nova_console_novnc_ssl.yml index c9ea4bf2..1a5fdb6e 100644 --- a/tasks/consoles/nova_console_novnc_ssl.yml +++ b/tasks/consoles/nova_console_novnc_ssl.yml @@ -39,6 +39,8 @@ with_items: - { content: "{{ nova_console_user_ssl_combined.stdout ~ '\n' }}", dest: "{{ nova_console_ssl_cert }}", mode: "0644" } - { src: "{{ nova_console_user_ssl_key }}", dest: "{{ nova_console_ssl_key }}", mode: "0640" } - notify: Restart nova services + notify: + - Manage LB + - Restart nova services tags: - nova-config diff --git a/tasks/nova_init_systemd.yml b/tasks/nova_init_systemd.yml index fd5c72bc..618366f2 100644 --- a/tasks/nova_init_systemd.yml +++ b/tasks/nova_init_systemd.yml @@ -49,6 +49,7 @@ group: "root" with_items: "{{ filtered_nova_services }}" notify: + - Manage LB - Restart nova services - name: Place the systemd init script @@ -62,4 +63,5 @@ config_type: "ini" with_items: "{{ filtered_nova_services }}" notify: + - Manage LB - Restart nova services diff --git a/tasks/nova_install.yml b/tasks/nova_install.yml index b9d73a25..94d42b8e 100644 --- a/tasks/nova_install.yml +++ b/tasks/nova_install.yml @@ -118,7 +118,9 @@ copy: "no" when: - nova_get_venv | changed - notify: Restart nova services + notify: + - Manage LB + - Restart nova services tags: - nova-pip-packages @@ -138,7 +140,9 @@ delay: 2 when: - nova_get_venv | failed or nova_get_venv | skipped - notify: Restart nova services + notify: + - Manage LB + - Restart nova services tags: - nova-pip-packages diff --git a/tasks/nova_post_install.yml b/tasks/nova_post_install.yml index 3821b800..49ffa2cc 100644 --- a/tasks/nova_post_install.yml +++ b/tasks/nova_post_install.yml @@ -51,7 +51,9 @@ dest: "/etc/nova/policy.json-{{ nova_venv_tag }}" config_overrides: "{{ nova_policy_overrides }}" config_type: "json" - notify: Restart nova services + notify: + - Manage LB + - Restart nova services tags: - nova-config - nova-post-install @@ -64,7 +66,9 @@ group: "root" with_fileglob: - rootwrap.d/* - notify: Restart nova services + notify: + - Manage LB + - Restart nova services tags: - nova-config - nova-post-install diff --git a/tasks/nova_uwsgi.yml b/tasks/nova_uwsgi.yml index e8aeefab..7400ddca 100644 --- a/tasks/nova_uwsgi.yml +++ b/tasks/nova_uwsgi.yml @@ -30,6 +30,7 @@ with_items: "{{ filtered_nova_services }}" when: item.wsgi_app | default(False) notify: + - Manage LB - Restart nova services # Cleanup and restart nginx configuration