Skip to content

Commit 95636c0

Browse files
authored
Wpb 22439 wiab dev fixes (#854)
* fix: wpb-22439 handle offline-env-wiab.sh for missing zauth images as zauth logic is handled in ansible * fix: wpb-22439 pipenv --break-system-packages arg and handle it with virtual env * fix: wpb-22439 optimized the logic for demo secret and values file management * fix: wpb-22439 move hairpin_networking playbook inside the helm_install playbook * fix: wpb-22439 remove non-required offline_deploy_k8s.sh bash script and add changelog * fix: wpb-22439 fix the shell lint issue * build: wpb-22439 update artifact hash for wiab-demo solution * build: wpb-22439 change documentation as per changes for hairpin_networking and python modules * fix: wpb-22439 modify zauth base65 secrets to be url-safe * fix: wpb-22439 tags when conditions for tasks to work properly * fix: wpb-22439 handle tr command better * fix: wpb-22439 update wiab-dev artifact hash
1 parent abf9d29 commit 95636c0

10 files changed

Lines changed: 189 additions & 365 deletions

File tree

ansible/inventory/demo/host.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ wiab:
1818
wire_ip: ""
1919

2020
# artifact_hash
21-
artifact_hash: "8e5087a0d9c58a9bd34c6c02f87514abe8b3ce0e"
21+
artifact_hash: "94523acf6df5a177fd7fc1a7fdc004ce5335233b"
2222

2323
# docker vars
2424
docker_ce_version: "5:28.1.1-1~ubuntu.24.04~noble"

ansible/wiab-demo/deploy_wiab.yml

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,62 @@
3636
import_playbook: ./install_pkgs.yml
3737
tags: install_pkgs
3838

39+
- name: Check and configure Ansible Python interpreter for Kubernetes operations
40+
tags: always
41+
hosts: deploy_node
42+
tasks:
43+
- name: Detect available Python interpreters and Kubernetes module
44+
block:
45+
- name: Check if kubernetes module is available in system Python
46+
shell: "python3 -c 'import kubernetes; print(kubernetes.__version__)' 2>/dev/null"
47+
register: system_k8s_check
48+
changed_when: false
49+
failed_when: false
50+
51+
- name: Check virtual environment only if system Python doesn't have kubernetes
52+
block:
53+
- name: Check if kubernetes module is available in virtual environment
54+
shell: "/opt/ansible-venv/bin/python -c 'import kubernetes; print(kubernetes.__version__)' 2>/dev/null"
55+
register: venv_k8s_check
56+
changed_when: false
57+
failed_when: false
58+
59+
- name: Configure to use virtual environment
60+
block:
61+
- name: Set ansible_python_interpreter to use virtual environment
62+
set_fact:
63+
ansible_python_interpreter: /opt/ansible-venv/bin/python
64+
ansible_venv_path: /opt/ansible-venv
65+
66+
when: venv_k8s_check.rc == 0
67+
68+
- name: Kubernetes module not found - run install_pkgs playbook
69+
fail:
70+
msg: |
71+
❌ Kubernetes Python module not found!
72+
73+
System Python (/usr/bin/python3):
74+
Status: NOT available
75+
76+
Virtual Environment (/opt/ansible-venv/bin/python):
77+
Status: NOT available
78+
79+
To install kubernetes module, run:
80+
ansible-playbook -i inventory.yml deploy_wiab.yml --tags install_pkgs
81+
when: venv_k8s_check.rc != 0
82+
83+
when: system_k8s_check.rc != 0
84+
3985
- name: Manage SSH keys (dependency for minikube, asset_host, seed_containers)
4086
import_playbook: ./setup_ssh.yml
4187
tags: always
4288
when: >
43-
(('minikube' not in ansible_skip_tags or
89+
('minikube' not in ansible_skip_tags or
4490
'asset_host' not in ansible_skip_tags or
4591
'seed_containers' not in ansible_skip_tags)
46-
and (ansible_skip_tags | length > 0))
47-
or
48-
('minikube' in ansible_run_tags or
92+
and
93+
('all' in ansible_run_tags or
94+
'minikube' in ansible_run_tags or
4995
'asset_host' in ansible_run_tags or
5096
'seed_containers' in ansible_run_tags)
5197
@@ -104,15 +150,16 @@
104150

105151
tags: always
106152
when: >
107-
(('minikube' not in ansible_skip_tags or
153+
('minikube' not in ansible_skip_tags or
108154
'asset_host' not in ansible_skip_tags or
109-
'seed_containers' not in ansible_skip_tags)
110-
and (ansible_skip_tags | length > 0))
111-
or
112-
('minikube' in ansible_run_tags or
155+
'seed_containers' not in ansible_skip_tags or
156+
'helm_install' not in ansible_skip_tags)
157+
and
158+
('all' in ansible_run_tags or
159+
'minikube' in ansible_run_tags or
113160
'asset_host' in ansible_run_tags or
114-
'seed_containers' in ansible_run_tags)
115-
or use_cert_manager
161+
'seed_containers' in ansible_run_tags or
162+
'helm_install' in ansible_run_tags)
116163
117164
- name: Configure Iptables rules
118165
import_playbook: ./iptables_rules.yml
@@ -126,6 +173,7 @@
126173
hosts: deploy_node
127174
become: yes
128175
become_user: "{{ ansible_user }}"
176+
tags: always
129177
tasks:
130178
- name: Create a block for Minikube node tasks
131179
block:
@@ -209,13 +257,12 @@
209257
delegate_facts: true
210258
with_items: "{{ groups['k8s-cluster'] }}"
211259

212-
tags: always
213260
when: >
214-
(('asset_host' not in ansible_skip_tags or
261+
('asset_host' not in ansible_skip_tags or
215262
'seed_containers' not in ansible_skip_tags)
216-
and (ansible_skip_tags | length > 0))
217-
or
218-
('asset_host' in ansible_run_tags or
263+
and
264+
('all' in ansible_run_tags or
265+
'asset_host' in ansible_run_tags or
219266
'seed_containers' in ansible_run_tags)
220267
221268
- name: Setup Asset Host
@@ -246,11 +293,6 @@
246293
import_playbook: ./helm_install.yml
247294
tags: helm_install
248295

249-
- name: Veirfy Cert Manager hairpin Networking
250-
import_playbook: ./hairpin_networking.yml
251-
tags: always
252-
when: use_cert_manager
253-
254296
# since, the temp_dir are created in a different set of tasks, these directories need to be searched
255297
- name: Clean up temporary directories
256298
hosts: localhost

ansible/wiab-demo/helm_install.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,7 @@
271271
- "For more information:"
272272
- "https://github.com/wireapp/wire-server/tree/develop/charts/nginx-ingress-services"
273273
when: not use_cert_manager
274+
275+
- name: Verify Cert Manager hairpin Networking
276+
import_playbook: ./hairpin_networking.yml
277+
when: use_cert_manager

ansible/wiab-demo/install_pkgs.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,30 @@
6565

6666
- name: Ensure required Python libraries are installed for Kubernetes operations
6767
block:
68-
- name: Install kubernetes Python library via pip
68+
- name: Create Python virtual environment for Ansible
69+
command: python3 -m venv /opt/ansible-venv
70+
args:
71+
creates: /opt/ansible-venv/bin/python
72+
become: yes
73+
74+
- name: Install kubernetes Python library in virtual environment
6975
pip:
7076
name:
7177
- kubernetes>=18.0.0
7278
- pyyaml>=5.4.1
73-
executable: /usr/bin/pip3
79+
executable: /opt/ansible-venv/bin/pip
7480
state: present
75-
extra_args: "--break-system-packages"
7681
become: yes
7782
register: pip_install_result
7883

84+
- name: Create symbolic link for ansible Python interpreter
85+
file:
86+
src: /opt/ansible-venv/bin/python
87+
dest: /usr/local/bin/ansible-python
88+
state: link
89+
force: yes
90+
become: yes
91+
7992
- name: Check if Docker CE is installed with correct version
8093
shell: apt policy docker-ce | grep "Installed:" | awk '{print $2}'
8194
register: installed_docker_version

ansible/wiab-demo/wire_secrets.yml

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -73,52 +73,43 @@
7373

7474
- name: Initialize secrets.yaml files from demo templates
7575
block:
76-
- name: Discover all chart directories in values_dir for initialization
76+
- name: Find all demo-secrets.example.yaml files in one pass
7777
find:
7878
paths: "{{ values_dir }}"
79-
file_type: directory
80-
recurse: no
81-
register: chart_dirs
79+
patterns: "demo-secrets.example.yaml"
80+
recurse: yes
81+
register: demo_secrets_files
82+
changed_when: false
8283

83-
- name: Verify demo-secrets.example.yaml template files exist
84-
stat:
85-
path: "{{ item.path }}/demo-secrets.example.yaml"
86-
register: demo_secrets_stat
87-
loop: "{{ chart_dirs.files }}"
84+
- name: Backup and initialize secrets for all charts
85+
shell: |
86+
#!/bin/bash
87+
set -e
88+
demo_file="{{ item }}"
89+
chart_dir="$(dirname "$demo_file")"
90+
secrets_file="$chart_dir/secrets.yaml"
91+
92+
# Create timestamped backup if secrets.yaml exists
93+
if [ -f "$secrets_file" ]; then
94+
backup_file="${secrets_file}.bak.$(date +%Y%m%d_%H%M%S)"
95+
mv "$secrets_file" "$backup_file"
96+
echo "Backed up: $backup_file"
97+
fi
98+
99+
# Copy demo template to secrets.yaml
100+
cp "$demo_file" "$secrets_file"
101+
echo "Initialized: $secrets_file"
102+
args:
103+
executable: /bin/bash
104+
register: init_result
105+
changed_when: "'Initialized:' in init_result.stdout"
106+
loop: "{{ demo_secrets_files.files | map(attribute='path') | list }}"
88107
no_log: true
89108

90-
- name: Create timestamped backups of existing secrets.yaml files
91-
block:
92-
- name: Check if secrets.yaml file exists before backup
93-
stat:
94-
path: "{{ item.item.path }}/secrets.yaml"
95-
register: secrets_file_stat
96-
loop: "{{ demo_secrets_stat.results }}"
97-
no_log: true
98-
99-
- name: Create backup with timestamp
100-
shell: |
101-
#!/bin/bash
102-
source_file="{{ item.item.path }}/secrets.yaml"
103-
backup_file="{{ item.item.path }}/secrets.yaml.bak.{{ lookup('pipe', 'date +%Y%m%d_%H%M%S') }}"
104-
if [ -f "$source_file" ]; then
105-
mv "$source_file" "$backup_file"
106-
fi
107-
args:
108-
executable: /bin/bash
109-
when: item.stat.exists
110-
loop: "{{ demo_secrets_stat.results }}"
111-
register: backup_result
112-
no_log: true
113-
114-
- name: Initialize secrets.yaml from demo template for each chart
115-
copy:
116-
src: "{{ item.item.path }}/demo-secrets.example.yaml"
117-
dest: "{{ item.item.path }}/secrets.yaml"
118-
remote_src: yes
119-
when: item.stat.exists
120-
loop: "{{ demo_secrets_stat.results }}"
121-
no_log: true
109+
- name: Display backup and initialization summary
110+
debug:
111+
msg: "{{ init_result.results | map(attribute='stdout_lines') | flatten | list }}"
112+
when: init_result.results | length > 0
122113

123114
when: not skip_secret_generation
124115

@@ -165,12 +156,9 @@
165156
set_fact:
166157
temp_dir: "{{ zauth_temp_dir.path }}"
167158

168-
- name: Generate Ed25519 private key in PEM format
169-
openssl_privatekey:
170-
path: "{{ temp_dir }}/key.pem"
171-
type: Ed25519
172-
force: yes
173-
no_log: true
159+
- name: Generate Ed25519 private key using openssl
160+
shell: "openssl genpkey -algorithm ed25519 -out '{{ temp_dir }}/key.pem'"
161+
changed_when: false
174162

175163
- name: Extract private key in DER format
176164
shell: "openssl pkey -in '{{ temp_dir }}/key.pem' -outform DER 2>/dev/null > '{{ temp_dir }}/priv.der'"
@@ -193,12 +181,12 @@
193181
changed_when: false
194182

195183
- name: Encode combined key to base64 (private key)
196-
shell: "base64 -w 0 < '{{ temp_dir }}/combined.bytes'"
184+
shell: "base64 -w 0 < '{{ temp_dir }}/combined.bytes' | tr -- '+/' '-_'"
197185
register: libsodium_priv
198186
changed_when: false
199187

200188
- name: Encode public key to base64
201-
shell: "base64 -w 0 < '{{ temp_dir }}/pub.bytes'"
189+
shell: "base64 -w 0 < '{{ temp_dir }}/pub.bytes' | tr -- '+/' '-_'"
202190
register: libsodium_pub
203191
changed_when: false
204192

@@ -230,29 +218,33 @@
230218
- name: Verify private key is valid base64
231219
assert:
232220
that:
233-
- libsodium_priv.stdout is regex('^[A-Za-z0-9+/]+=*$')
221+
- libsodium_priv.stdout is regex('^[A-Za-z0-9_-]+=*$')
234222
fail_msg: "Private key is not valid base64: {{ libsodium_priv.stdout }}"
235223
quiet: yes
236224

237225
- name: Verify public key is valid base64
238226
assert:
239227
that:
240-
- libsodium_pub.stdout is regex('^[A-Za-z0-9+/]+=*$')
228+
- libsodium_pub.stdout is regex('^[A-Za-z0-9_-]+=*$')
241229
fail_msg: "Public key is not valid base64: {{ libsodium_pub.stdout }}"
242230
quiet: yes
243231

244232
- name: Validate decoded key lengths
245233
block:
246234
- name: Decode and verify private key length (should be 64 bytes)
247-
shell: "echo '{{ libsodium_priv.stdout }}' | base64 -d | wc -c"
235+
shell: "printf '%s' '{{ libsodium_priv.stdout }}' | tr -- '-_' '+/' | base64 -d | wc -c"
248236
register: priv_decoded_len
249237
changed_when: false
250238

251239
- name: Decode and verify public key length (should be 32 bytes)
252-
shell: "echo '{{ libsodium_pub.stdout }}' | base64 -d | wc -c"
240+
shell: "printf '%s' '{{ libsodium_pub.stdout }}' | tr -- '-_' '+/' | base64 -d | wc -c"
253241
register: pub_decoded_len
254242
changed_when: false
255243

244+
- name: debug
245+
debug:
246+
msg: " {{libsodium_pub.stdout}} {{libsodium_priv.stdout }}"
247+
256248
- name: Assert decoded key lengths are correct
257249
assert:
258250
that:

0 commit comments

Comments
 (0)