|
6 | 6 | vars: |
7 | 7 | rpk_bin: rpk |
8 | 8 |
|
| 9 | + # SASL/TLS settings for authenticated clusters |
| 10 | + kafka_enable_authorization: false |
| 11 | + admin_api_require_auth: false |
| 12 | + sasl_superuser_username: "admin" |
| 13 | + sasl_superuser_password: "" |
| 14 | + enable_tls: false |
| 15 | + redpanda_truststore_file: /etc/redpanda/certs/truststore.pem |
| 16 | + redpanda_kafka_port: 9092 |
| 17 | + |
| 18 | + rpk_opts: >- |
| 19 | + -X brokers={{ hostvars[inventory_hostname].private_ip | default(ansible_default_ipv4.address) }}:{{ redpanda_kafka_port }} |
| 20 | + {% if enable_tls | default(false) %}-X tls.enabled=true -X tls.ca={{ redpanda_truststore_file }}{% endif %} |
| 21 | + {% if kafka_enable_authorization | default(false) and sasl_superuser_password != '' %}-X user={{ sasl_superuser_username }} -X pass={{ sasl_superuser_password }} -X sasl.mechanism=SCRAM-SHA-256{% endif %} |
| 22 | +
|
| 23 | + rpk_admin_opts: >- |
| 24 | + {% if enable_tls | default(false) %}-X admin.tls.enabled=true -X admin.tls.ca={{ redpanda_truststore_file }}{% endif %} |
| 25 | + {% if admin_api_require_auth | default(false) and sasl_superuser_password != '' %}-X user={{ sasl_superuser_username }} -X pass={{ sasl_superuser_password }}{% endif %} |
| 26 | +
|
9 | 27 | tasks: |
10 | 28 | - name: Check cluster health |
11 | 29 | ansible.builtin.shell: | |
12 | | - {{ rpk_bin }} cluster health | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
| 30 | + {{ rpk_bin }} cluster health {{ rpk_opts }} {{ rpk_admin_opts }} | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
13 | 31 | register: health_check |
14 | 32 | failed_when: "health_check.stdout != 'true'" |
15 | 33 | changed_when: false |
| 34 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
16 | 35 |
|
17 | 36 | - name: Get node ID |
18 | 37 | ansible.builtin.shell: | |
19 | | - {{ rpk_bin }} cluster info | awk '$2 == "{{ ansible_host }}" {gsub("\\*", "", $1); print $1}' |
| 38 | + {{ rpk_bin }} cluster info {{ rpk_opts }} | awk '$2 == "{{ ansible_host }}" {gsub("\\*", "", $1); print $1}' |
20 | 39 | register: node_id |
21 | 40 | changed_when: false |
| 41 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
22 | 42 |
|
23 | 43 | - name: Enable maintenance mode |
24 | | - ansible.builtin.command: "{{ rpk_bin }} cluster maintenance enable {{ node_id.stdout }} --wait" |
| 44 | + ansible.builtin.command: "{{ rpk_bin }} cluster maintenance enable {{ node_id.stdout }} --wait {{ rpk_opts }} {{ rpk_admin_opts }}" |
25 | 45 | register: maintenance_result |
26 | 46 | failed_when: |
27 | 47 | - "'Successfully enabled maintenance mode' not in maintenance_result.stdout" |
28 | 48 | - "'Maintenance mode is already enabled for node' not in maintenance_result.stdout" |
29 | 49 | changed_when: "'Successfully enabled maintenance mode' in maintenance_result.stdout" |
| 50 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
30 | 51 |
|
31 | 52 | - name: Verify maintenance mode status |
32 | 53 | ansible.builtin.shell: | |
33 | | - {{ rpk_bin }} cluster maintenance status | grep -q '{{ node_id.stdout }}' |
| 54 | + {{ rpk_bin }} cluster maintenance status {{ rpk_opts }} {{ rpk_admin_opts }} | grep -q '{{ node_id.stdout }}' |
34 | 55 | register: maintenance_status |
35 | 56 | failed_when: maintenance_status.rc != 0 |
36 | 57 | changed_when: false |
| 58 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
37 | 59 |
|
38 | 60 | - name: Check cluster health after enabling maintenance mode |
39 | 61 | ansible.builtin.shell: | |
40 | | - {{ rpk_bin }} cluster health --watch --exit-when-healthy | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
| 62 | + {{ rpk_bin }} cluster health --watch --exit-when-healthy {{ rpk_opts }} {{ rpk_admin_opts }} | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
41 | 63 | register: health_check_maintenance |
42 | 64 | failed_when: "health_check_maintenance.stdout != 'true'" |
43 | 65 | retries: 10 |
44 | 66 | delay: 30 |
45 | 67 | changed_when: false |
| 68 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
46 | 69 |
|
47 | 70 | - name: Stop Redpanda service |
48 | 71 | ansible.builtin.systemd: |
|
55 | 78 | state: started |
56 | 79 |
|
57 | 80 | - name: Disable maintenance mode |
58 | | - ansible.builtin.command: "{{ rpk_bin }} cluster maintenance disable {{ node_id.stdout }}" |
| 81 | + ansible.builtin.command: "{{ rpk_bin }} cluster maintenance disable {{ node_id.stdout }} {{ rpk_opts }} {{ rpk_admin_opts }}" |
59 | 82 | register: disable_maintenance_result |
60 | 83 | changed_when: "'Successfully disabled maintenance mode' in disable_maintenance_result.stdout" |
61 | 84 | failed_when: "'Successfully disabled maintenance mode' not in disable_maintenance_result.stdout" |
| 85 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
62 | 86 |
|
63 | 87 | - name: Verify maintenance mode is disabled |
64 | 88 | ansible.builtin.shell: | |
65 | | - {{ rpk_bin }} cluster maintenance status | grep -qv '{{ node_id.stdout }}' |
| 89 | + {{ rpk_bin }} cluster maintenance status {{ rpk_opts }} {{ rpk_admin_opts }} | grep -qv '{{ node_id.stdout }}' |
66 | 90 | register: maintenance_status_after |
67 | 91 | failed_when: maintenance_status_after.rc != 0 |
68 | 92 | changed_when: false |
| 93 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
69 | 94 |
|
70 | 95 | - name: Check cluster health after disabling maintenance mode |
71 | 96 | ansible.builtin.shell: | |
72 | | - {{ rpk_bin }} cluster health --watch --exit-when-healthy | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
| 97 | + {{ rpk_bin }} cluster health --watch --exit-when-healthy {{ rpk_opts }} {{ rpk_admin_opts }} | grep -i 'healthy:' | tr -d '[:space:]' | awk -F ':' '{print tolower($2)}' |
73 | 98 | register: health_check_maintenance |
74 | 99 | failed_when: "health_check_maintenance.stdout != 'true'" |
75 | 100 | retries: 10 |
76 | 101 | delay: 30 |
77 | 102 | changed_when: false |
| 103 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
78 | 104 |
|
79 | 105 | - name: Check broker status |
80 | 106 | ansible.builtin.shell: | |
81 | | - {{ rpk_bin }} redpanda admin brokers list | grep -q 'active.*true' |
| 107 | + {{ rpk_bin }} redpanda admin brokers list {{ rpk_admin_opts }} | grep -q 'active.*true' |
82 | 108 | register: broker_status |
83 | 109 | changed_when: false |
84 | 110 | failed_when: broker_status.rc != 0 |
| 111 | + no_log: "{{ kafka_enable_authorization | default(false) }}" |
0 commit comments