From e4644a19fc92512c9a33d91720e743f7dd88dcd4 Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Tue, 12 Jul 2016 11:21:33 -0400 Subject: [PATCH] Make rabbitmq inventory group configurable The default value of "rabbitmq_all" remains, but this change should allow deployers to target the role to multiple groups now. Change-Id: Idc1bc44b005f09f9dc7eb9778719a8ba92756c06 Implements: blueprint multi-rabbitmq-clusters --- defaults/main.yml | 5 ++++- .../configurable_inventory_group-9f5b193221b7006d.yaml | 7 +++++++ tasks/rabbitmq_post_install.yml | 4 ++-- tasks/rabbitmq_pre_install.yml | 2 +- tasks/rabbitmq_ssl_key_distribute.yml | 4 ++-- tasks/rabbitmq_ssl_self_signed.yml | 6 +++--- tests/inventory | 4 ++-- tests/test-install-rabbitmq-server.yml | 2 +- tests/test-rabbitmq-server-functional.yml | 2 +- tests/test-vars.yml | 1 + 10 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 releasenotes/notes/configurable_inventory_group-9f5b193221b7006d.yaml diff --git a/defaults/main.yml b/defaults/main.yml index c2666092..1ff128f6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -16,7 +16,10 @@ ## APT Cache Options cache_timeout: 600 -rabbitmq_primary_cluster_node: "{{ hostvars[groups['rabbitmq_all'][0]]['ansible_hostname'] }}" +# Inventory group containing the hosts for the cluster +rabbitmq_host_group: "rabbitmq_all" + +rabbitmq_primary_cluster_node: "{{ hostvars[groups[rabbitmq_host_group][0]]['ansible_hostname'] }}" # Upgrading the RabbitMQ package requires shutting down the cluster. This variable makes upgrading # the version an explicit action. diff --git a/releasenotes/notes/configurable_inventory_group-9f5b193221b7006d.yaml b/releasenotes/notes/configurable_inventory_group-9f5b193221b7006d.yaml new file mode 100644 index 00000000..c334b92a --- /dev/null +++ b/releasenotes/notes/configurable_inventory_group-9f5b193221b7006d.yaml @@ -0,0 +1,7 @@ +--- +features: + - The ``rabbitmq_server`` now supports a configurable inventory + host group. Deployers can override the ``rabbitmq_host_group`` variable + if they wish to use the role to create additional RabbitMQ clusters + on a custom host group. + diff --git a/tasks/rabbitmq_post_install.yml b/tasks/rabbitmq_post_install.yml index e5376e38..c7f574a1 100644 --- a/tasks/rabbitmq_post_install.yml +++ b/tasks/rabbitmq_post_install.yml @@ -56,7 +56,7 @@ rabbitmq_user: user: guest state: absent - when: inventory_hostname == groups['rabbitmq_all'][0] + when: inventory_hostname == groups[rabbitmq_host_group][0] tags: - rabbitmq-user @@ -64,6 +64,6 @@ rabbitmq_user: user: guest state: absent - when: inventory_hostname != groups['rabbitmq_all'][0] + when: inventory_hostname != groups[rabbitmq_host_group][0] tags: - rabbitmq-user diff --git a/tasks/rabbitmq_pre_install.yml b/tasks/rabbitmq_pre_install.yml index 973ee4fe..edffca38 100644 --- a/tasks/rabbitmq_pre_install.yml +++ b/tasks/rabbitmq_pre_install.yml @@ -45,7 +45,7 @@ dest: /etc/hosts state: present line: "{{ hostvars[item]['ansible_ssh_host'] }} {{ hostvars[item]['ansible_hostname'] }} {{ hostvars[item]['ansible_hostname'].split('.')[0] }}" - with_items: "{{ groups['rabbitmq_all'] }}" + with_items: "{{ groups[rabbitmq_host_group] }}" tags: - rabbitmq-config diff --git a/tasks/rabbitmq_ssl_key_distribute.yml b/tasks/rabbitmq_ssl_key_distribute.yml index 91ae08e6..dbc9b346 100644 --- a/tasks/rabbitmq_ssl_key_distribute.yml +++ b/tasks/rabbitmq_ssl_key_distribute.yml @@ -16,7 +16,7 @@ - name: Distribute self signed ssl key copy: dest: "{{ rabbitmq_ssl_key }}" - content: "{{ hostvars[groups['rabbitmq_all'][0]]['rabbitmq_ssl_key_fact'] | b64decode }}" + content: "{{ hostvars[groups[rabbitmq_host_group][0]]['rabbitmq_ssl_key_fact'] | b64decode }}" owner: "rabbitmq" group: "rabbitmq" mode: "0640" @@ -26,7 +26,7 @@ - name: Distribute self signed ssl cert copy: dest: "{{ rabbitmq_ssl_cert }}" - content: "{{ hostvars[groups['rabbitmq_all'][0]]['rabbitmq_ssl_cert_fact'] | b64decode }}" + content: "{{ hostvars[groups[rabbitmq_host_group][0]]['rabbitmq_ssl_cert_fact'] | b64decode }}" owner: "rabbitmq" group: "rabbitmq" mode: "0640" diff --git a/tasks/rabbitmq_ssl_self_signed.yml b/tasks/rabbitmq_ssl_self_signed.yml index 3ee5b9a2..0cab33cc 100644 --- a/tasks/rabbitmq_ssl_self_signed.yml +++ b/tasks/rabbitmq_ssl_self_signed.yml @@ -17,12 +17,12 @@ # RabbitMQ container. - include: rabbitmq_ssl_key_create.yml when: > - inventory_hostname == groups['rabbitmq_all'][0] + inventory_hostname == groups[rabbitmq_host_group][0] - include: rabbitmq_ssl_key_store.yml when: > - inventory_hostname == groups['rabbitmq_all'][0] + inventory_hostname == groups[rabbitmq_host_group][0] - include: rabbitmq_ssl_key_distribute.yml when: > - inventory_hostname != groups['rabbitmq_all'][0] + inventory_hostname != groups[rabbitmq_host_group][0] diff --git a/tests/inventory b/tests/inventory index e61c1d71..df4660c8 100644 --- a/tests/inventory +++ b/tests/inventory @@ -4,10 +4,10 @@ container1 ansible_ssh_host=10.100.100.101 ansible_host=10.100.100.101 ansible_b container2 ansible_ssh_host=10.100.100.102 ansible_host=10.100.100.102 ansible_become=True ansible_user=root container3 ansible_ssh_host=10.100.100.103 ansible_host=10.100.100.103 ansible_become=True ansible_user=root -[rabbitmq_all] +[rabbitmq_all_other] container1 container2 container3 [all_containers:children] -rabbitmq_all +rabbitmq_all_other diff --git a/tests/test-install-rabbitmq-server.yml b/tests/test-install-rabbitmq-server.yml index 3f23f930..2aa54f44 100644 --- a/tests/test-install-rabbitmq-server.yml +++ b/tests/test-install-rabbitmq-server.yml @@ -16,7 +16,7 @@ # NOTE(mancdaz): rabbitmq cannot be upgraded in serial, so when # rabbitmq_upgrade=True, serial is set to 0, else it is 1 for installs - name: Install RabbitMQ server - hosts: rabbitmq_all + hosts: "{{ rabbitmq_host_group }}" serial: "{{ rabbitmq_upgrade|default(false) | bool | ternary(0, 1)}}" user: root gather_facts: true diff --git a/tests/test-rabbitmq-server-functional.yml b/tests/test-rabbitmq-server-functional.yml index 9d48c5d0..c2b709f5 100644 --- a/tests/test-rabbitmq-server-functional.yml +++ b/tests/test-rabbitmq-server-functional.yml @@ -14,7 +14,7 @@ # limitations under the License. - name: Run functional tests - hosts: rabbitmq_all + hosts: "{{ rabbitmq_host_group }}" user: root gather_facts: true vars_files: diff --git a/tests/test-vars.yml b/tests/test-vars.yml index c09b8c97..71f77766 100644 --- a/tests/test-vars.yml +++ b/tests/test-vars.yml @@ -1,3 +1,4 @@ +rabbitmq_host_group: "rabbitmq_all_other" rabbitmq_cookie_token: secrete rabbitmq_ssl_cert: /etc/rabbitmq/rabbitmq.pem rabbitmq_ssl_key: /etc/rabbitmq/rabbitmq.key