Merge "Move RabbitMQ restart to handlers"

This commit is contained in:
Zuul
2024-11-20 10:36:43 +00:00
committed by Gerrit Code Review
9 changed files with 113 additions and 137 deletions

View File

@@ -1,5 +1,5 @@
---
# Copyright 2014, Rackspace US, Inc.
# Copyright 2024, Cleura AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -13,26 +13,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Including rabbitmq_stopped tasks
include_tasks: rabbitmq_stopped.yml
args:
apply:
tags:
- rabbitmq-restart
tags:
- always
- name: "Ensure RabbitMQ is stopped"
service:
name: rabbitmq-server
state: stopped
listen:
- RabbitMQ stop
- RabbitMQ restart
- name: Including rabbitmq_started tasks
include_tasks: rabbitmq_started.yml
args:
apply:
tags:
- rabbitmq-restart
tags:
- always
- name: "Ensure RabbitMQ is started"
service:
name: rabbitmq-server
state: started
enabled: yes
listen:
- RabbitMQ start
- RabbitMQ restart
- name: Wait for rabbitmq to be started
wait_for:
host: "{{ item.key }}"
port: "{{ item.value }}"
loop: "{{ query('dict', rabbitmq_port_bindings.tcp_listeners) }}"
listen:
- RabbitMQ start
- RabbitMQ restart

View File

@@ -95,6 +95,8 @@
until: install_packages is success
retries: 5
delay: 2
notify:
- RabbitMQ restart
tags:
- rabbitmq-apt-packages
@@ -102,6 +104,8 @@
apt:
deb: "{{ rabbitmq_package_path }}"
register: install_rabbitmq
notify:
- RabbitMQ restart
when:
- rabbitmq_install_method == 'file'
tags:
@@ -116,6 +120,8 @@
until: install_packages is success
retries: 5
delay: 2
notify:
- RabbitMQ restart
when:
- rabbitmq_install_method != 'file'
tags:

View File

@@ -48,6 +48,8 @@
yum:
name: "{{ rabbitmq_distro_packages }}"
state: "{{ rabbitmq_package_state }}"
notify:
- RabbitMQ restart
register: install_rabbitmq
tags:
- rabbitmq-package-rpm

View File

@@ -61,26 +61,31 @@
pki_certificates: "{{ rabbitmq_pki_certificates }}"
pki_install_certificates: "{{ rabbitmq_pki_install_certificates }}"
- name: Importing rabbitmq_set_cookie tasks
import_tasks: rabbitmq_set_cookie.yml
tags:
- rabbitmq_server-config
- rabbitmq-config
- name: Importing rabbitmq_post_install tasks
import_tasks: rabbitmq_post_install.yml
tags:
- rabbitmq_server-config
- rabbitmq-config
- name: Flush handlers
meta: flush_handlers
- name: Importing rabbitmq_cluster tasks
import_tasks: rabbitmq_cluster.yml
tags:
- rabbitmq_server-config
- rabbitmq-cluster
- name: Flush handlers
meta: flush_handlers
- name: Including rabbitmq_setup tasks
include_tasks: rabbitmq_setup.yml
when:
- _rabbitmq_is_last_play_host
args:
apply:
tags:
- rabbitmq_server-config
tags:
- rabbitmq_server-config
- name: Ensure all flags are set after upgrade is done
when:

View File

@@ -13,8 +13,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Set rabbit cookie
copy:
content: "{{ rabbitmq_cookie_token }}"
dest: /var/lib/rabbitmq/.erlang.cookie
mode: "0400"
owner: rabbitmq
group: rabbitmq
register: cookie_set
notify:
- RabbitMQ restart
tags:
- rabbitmq-config
- name: Create rabbitmq config
register: rabbit_config
template:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
@@ -26,6 +38,8 @@
- { src: "advanced.config.j2", dest: "/etc/rabbitmq/advanced.config" }
- { src: "rabbitmq-server.j2", dest: "/etc/default/rabbitmq-server", mode: "0644" }
- { src: "rabbitmq-env.j2", dest: "/etc/rabbitmq/rabbitmq-env.conf" }
notify:
- RabbitMQ restart
tags:
- rabbitmq-config
@@ -46,53 +60,7 @@
state: "{{ item.state }}"
broker_state: offline
with_items: "{{ rabbitmq_plugins }}"
register: rabbitmq_plugin
notify:
- RabbitMQ restart
tags:
- rabbitmq-config
- name: Including rabbitmq_restart tasks
include_tasks:
file: rabbitmq_restart.yml
apply:
tags: rabbitmq-config
when: rabbit_config is changed or rabbitmq_plugin is changed or (cookie_set is defined and cookie_set is changed) or rabbitmq_upgrade | bool
tags:
- rabbitmq-config
- name: Apply rabbitmq policies
community.rabbitmq.rabbitmq_policy:
node: "rabbit@{{ ansible_facts['hostname'] }}"
name: "{{ item.name }}"
pattern: "{{ item.pattern }}"
apply_to: "{{ item.apply_to | default(omit) }}"
priority: "{{ item.priority | default(0) }}"
state: "{{ item.state | default(omit) }}"
tags: "{{ item.tags }}"
register: rabbitmq_policy
loop: "{{ (rabbitmq_apply_openstack_policies | bool) | ternary(rabbitmq_openstack_policies + rabbitmq_policies, rabbitmq_policies) }}"
tags:
- rabbitmq-config
- rabbitmq-cluster
# This is being done because the rabbitctl command used by the module
# is not very effective at returning proper status codes for failure
# and the module does not error detection. until we can go upstream
# to fix this issue this task being being done in two parts to ensure
# that the "guest" user is eradicated.
- name: Ensure default rabbitmq guest user is removed
community.rabbitmq.rabbitmq_user:
node: "rabbit@{{ ansible_facts['hostname'] }}"
user: guest
state: absent
when: inventory_hostname == groups[rabbitmq_host_group][0]
tags:
- rabbitmq-user
- name: Ensure default rabbitmq guest user is removed
community.rabbitmq.rabbitmq_user:
node: "rabbit@{{ ansible_facts['hostname'] }}"
user: guest
state: absent
when: inventory_hostname != groups[rabbitmq_host_group][0]
tags:
- rabbitmq-user

View File

@@ -1,23 +0,0 @@
---
# Copyright 2014, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Set rabbit cookie
copy:
content: "{{ rabbitmq_cookie_token }}"
dest: /var/lib/rabbitmq/.erlang.cookie
mode: "0400"
owner: rabbitmq
group: rabbitmq
register: cookie_set

52
tasks/rabbitmq_setup.yml Normal file
View File

@@ -0,0 +1,52 @@
---
# Copyright 2024, Cleura AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Apply rabbitmq policies
community.rabbitmq.rabbitmq_policy:
node: "rabbit@{{ ansible_facts['hostname'] }}"
name: "{{ item.name }}"
pattern: "{{ item.pattern }}"
apply_to: "{{ item.apply_to | default(omit) }}"
priority: "{{ item.priority | default(0) }}"
state: "{{ item.state | default(omit) }}"
tags: "{{ item.tags }}"
register: rabbitmq_policy
loop: "{{ (rabbitmq_apply_openstack_policies | bool) | ternary(rabbitmq_openstack_policies + rabbitmq_policies, rabbitmq_policies) }}"
tags:
- rabbitmq-config
- rabbitmq-cluster
# This is being done because the rabbitctl command used by the module
# is not very effective at returning proper status codes for failure
# and the module does not error detection. until we can go upstream
# to fix this issue this task being being done in two parts to ensure
# that the "guest" user is eradicated.
- name: Ensure default rabbitmq guest user is removed
community.rabbitmq.rabbitmq_user:
node: "rabbit@{{ ansible_facts['hostname'] }}"
user: guest
state: absent
when: inventory_hostname == groups[rabbitmq_host_group][0]
tags:
- rabbitmq-user
- name: Ensure default rabbitmq guest user is removed
community.rabbitmq.rabbitmq_user:
node: "rabbit@{{ ansible_facts['hostname'] }}"
user: guest
state: absent
when: inventory_hostname != groups[rabbitmq_host_group][0]
tags:
- rabbitmq-user

View File

@@ -1,38 +0,0 @@
---
# Copyright 2014, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: "Ensure RabbitMQ node [0] is started"
service:
name: rabbitmq-server
state: started
enabled: yes
when:
- ansible_facts['hostname'] == rabbitmq_primary_cluster_node
tags:
- rabbitmq-server-started
- rabbitmq-upgrade
- rabbitmq-start
- name: "Ensure RabbitMQ nodes [1:] are started"
service:
name: rabbitmq-server
state: started
enabled: yes
when:
- ansible_facts['hostname'] != rabbitmq_primary_cluster_node
tags:
- rabbitmq-server-started
- rabbitmq-upgrade
- rabbitmq-start

View File

@@ -31,5 +31,7 @@
pause:
seconds: 10
- name: Including rabbitmq_stopped tasks
import_tasks: rabbitmq_stopped.yml
- name: "Ensure RabbitMQ is stopped"
service:
name: rabbitmq-server
state: stopped