Use rabbitmq_cluster_state task instead of command
We can simplify logic and re-use rabbitmq_cluster_state tasks to fetch the current state of the cluster in a dictionary, which allows to avoid unnecessary today parsing of rabbitmq output. Change-Id: Ib99fcb1a3e0092bf96143435a0c876ab6f286f36
This commit is contained in:
@@ -13,34 +13,18 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# The output of 'rabbitmqctl -q cluster_status' looks like this:
|
- name: Importing rabbitmq_cluster_state tasks
|
||||||
# [{nodes,[{disc,[rabbit@container1,rabbit@container2,rabbit@container3]}]},
|
import_tasks: rabbitmq_cluster_state.yml
|
||||||
# {running_nodes,[rabbit@container3,rabbit@container1,rabbit@container2]},
|
|
||||||
# {cluster_name,
|
|
||||||
# <<"rabbitmq_cluster1">>},
|
|
||||||
# {partitions,[]},
|
|
||||||
# {alarms,[{rabbit@container3,[]},
|
|
||||||
# {rabbit@container1,[]},
|
|
||||||
# {rabbit@container2,[]}]}]
|
|
||||||
#
|
|
||||||
# Our solution to get the cluster name out cleanly is inspired by
|
|
||||||
# https://unix.stackexchange.com/a/13472
|
|
||||||
- name: Get rabbitmq cluster name
|
|
||||||
shell: rabbitmqctl -q cluster_status | sed 's/ //g' | grep -oP '(?<=Clustername:).*'
|
|
||||||
args:
|
|
||||||
executable: /bin/bash
|
|
||||||
changed_when: false
|
|
||||||
register: _cluster_name
|
|
||||||
|
|
||||||
- name: Set rabbitmq cluster name on primary node # noqa: no-changed-when
|
- name: Set rabbitmq cluster name on primary node # noqa: no-changed-when
|
||||||
command: |
|
command: |
|
||||||
rabbitmqctl set_cluster_name {{ rabbitmq_cluster_name }}
|
rabbitmqctl set_cluster_name {{ rabbitmq_cluster_name }}
|
||||||
when:
|
when:
|
||||||
- "ansible_facts['hostname'] == rabbitmq_primary_cluster_node"
|
- "ansible_facts['hostname'] == rabbitmq_primary_cluster_node"
|
||||||
- "_cluster_name.stdout != rabbitmq_cluster_name"
|
- "_cluster_state.get('cluster_name') != rabbitmq_cluster_name"
|
||||||
|
|
||||||
- name: Join cluster on secondary nodes
|
- name: Join cluster on secondary nodes
|
||||||
include_tasks: rabbitmq_cluster_join.yml
|
include_tasks: rabbitmq_cluster_join.yml
|
||||||
when:
|
when:
|
||||||
- "ansible_facts['hostname'] != rabbitmq_primary_cluster_node"
|
- "ansible_facts['hostname'] != rabbitmq_primary_cluster_node"
|
||||||
- "_cluster_name.stdout != rabbitmq_cluster_name"
|
- "_cluster_state.get('cluster_name') != rabbitmq_cluster_name"
|
||||||
|
|||||||
Reference in New Issue
Block a user