Use json formatter for feature_flags fetcher

We can replace shell with a simple command using json formatter,
which allows us to select only missing flags and enable them expclicitly
rather then enable all flags.
This also produces a better log, representing which flags were missing.

Change-Id: Idb5c02109458771853e0fdbc7f6bb27beaa731b4
This commit is contained in:
Dmitriy Rabotyagov
2024-10-09 13:40:22 +02:00
parent 6b4a766db6
commit aecf15d5ad

View File

@@ -24,20 +24,17 @@
- name: "Only enable feature flags if all cluster members are up and stable"
block:
- name: "Check for disabled RabbitMQ feature flags"
shell: "rabbitmqctl list_feature_flags | grep disabled"
args:
executable: /bin/bash
command: "rabbitmqctl list_feature_flags --formatter json name state stability"
register: _feature_flags
changed_when: False
failed_when: False
# NOTE: changed_when required despite the above check because 'unstable'
# feature flags will remain disabled each time this runs
- name: "Enable all RabbitMQ feature flags"
command: "rabbitmqctl enable_feature_flag all"
changed_when: False
when:
- (_feature_flags.stdout_lines | length) > 0
- name: "Enable missing RabbitMQ feature flags"
command: "rabbitmqctl enable_feature_flag {{ flag['name'] }}"
changed_when: True
loop: "{{ _feature_flags.stdout | from_json | rejectattr('stability', 'eq', 'experimental') | selectattr('state', 'eq', 'disabled') }}"
loop_control:
loop_var: flag
when:
- _cluster_status.rc == 0
- ((_cluster_status.stdout | from_json)['running_nodes'] | length) == (groups[rabbitmq_host_group] | length)