From 5108e06793e898a14c941dd7c09a8054cf010f6d Mon Sep 17 00:00:00 2001 From: Logan V Date: Sat, 16 Sep 2017 13:53:56 -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: I19818234d9c8a5ad90b6387c360d598fda03a65e --- doc/source/index.rst | 14 +++++++++++++- handlers/main.yml | 4 ++++ tasks/cinder_init_systemd.yml | 2 ++ tasks/cinder_install.yml | 8 ++++++-- tasks/cinder_post_install.yml | 2 ++ tasks/cinder_uwsgi.yml | 1 + 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 318b090c..dd690973 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -47,6 +47,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 ~~~~ @@ -56,4 +69,3 @@ The ``cinder-install`` tag can be used to install and upgrade. The ``cinder-config`` tag can be used to maintain configuration of the service. - diff --git a/handlers/main.yml b/handlers/main.yml index d88cdeb8..b31d9029 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -67,3 +67,7 @@ enabled: yes state: restarted daemon_reload: "{{ (ansible_service_mgr == 'systemd') | ternary('yes', omit) }}" + +- meta: noop + listen: Manage LB + when: false diff --git a/tasks/cinder_init_systemd.yml b/tasks/cinder_init_systemd.yml index d22cb762..62b9096e 100644 --- a/tasks/cinder_init_systemd.yml +++ b/tasks/cinder_init_systemd.yml @@ -50,6 +50,7 @@ group: "root" with_items: "{{ filtered_cinder_services }}" notify: + - Manage LB - Restart cinder services - name: Place the systemd init script @@ -63,4 +64,5 @@ config_type: "ini" with_items: "{{ filtered_cinder_services }}" notify: + - Manage LB - Restart cinder services diff --git a/tasks/cinder_install.yml b/tasks/cinder_install.yml index 71855dd2..ef0ec1d5 100644 --- a/tasks/cinder_install.yml +++ b/tasks/cinder_install.yml @@ -80,7 +80,9 @@ dest: "{{ cinder_bin | dirname }}" copy: "no" when: cinder_get_venv | changed - notify: Restart cinder services + notify: + - Manage LB + - Restart cinder services - name: Install pip packages pip: @@ -97,7 +99,9 @@ retries: 5 delay: 2 when: cinder_get_venv | failed or cinder_get_venv | skipped - notify: Restart cinder services + notify: + - Manage LB + - Restart cinder services - name: Remove python from path first (CentOS, openSUSE) file: diff --git a/tasks/cinder_post_install.yml b/tasks/cinder_post_install.yml index 1fa3f57f..048de668 100644 --- a/tasks/cinder_post_install.yml +++ b/tasks/cinder_post_install.yml @@ -40,6 +40,7 @@ config_overrides: "{{ cinder_policy_overrides }}" config_type: "json" notify: + - Manage LB - Restart cinder services - name: Copy cinder configs @@ -51,6 +52,7 @@ with_fileglob: - rootwrap.d/* notify: + - Manage LB - Restart cinder services - name: Ensure cinder tgt include diff --git a/tasks/cinder_uwsgi.yml b/tasks/cinder_uwsgi.yml index c0a70562..d18f7ea0 100644 --- a/tasks/cinder_uwsgi.yml +++ b/tasks/cinder_uwsgi.yml @@ -29,4 +29,5 @@ with_items: "{{ filtered_cinder_services }}" when: item.wsgi_app | default(False) notify: + - Manage LB - Restart cinder services