|
36 | 36 | import_playbook: ./install_pkgs.yml |
37 | 37 | tags: install_pkgs |
38 | 38 |
|
| 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 | + |
39 | 85 | - name: Manage SSH keys (dependency for minikube, asset_host, seed_containers) |
40 | 86 | import_playbook: ./setup_ssh.yml |
41 | 87 | tags: always |
42 | 88 | when: > |
43 | | - (('minikube' not in ansible_skip_tags or |
| 89 | + ('minikube' not in ansible_skip_tags or |
44 | 90 | 'asset_host' not in ansible_skip_tags or |
45 | 91 | '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 |
49 | 95 | 'asset_host' in ansible_run_tags or |
50 | 96 | 'seed_containers' in ansible_run_tags) |
51 | 97 |
|
|
104 | 150 |
|
105 | 151 | tags: always |
106 | 152 | when: > |
107 | | - (('minikube' not in ansible_skip_tags or |
| 153 | + ('minikube' not in ansible_skip_tags or |
108 | 154 | '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 |
113 | 160 | '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) |
116 | 163 |
|
117 | 164 | - name: Configure Iptables rules |
118 | 165 | import_playbook: ./iptables_rules.yml |
|
126 | 173 | hosts: deploy_node |
127 | 174 | become: yes |
128 | 175 | become_user: "{{ ansible_user }}" |
| 176 | + tags: always |
129 | 177 | tasks: |
130 | 178 | - name: Create a block for Minikube node tasks |
131 | 179 | block: |
|
209 | 257 | delegate_facts: true |
210 | 258 | with_items: "{{ groups['k8s-cluster'] }}" |
211 | 259 |
|
212 | | - tags: always |
213 | 260 | when: > |
214 | | - (('asset_host' not in ansible_skip_tags or |
| 261 | + ('asset_host' not in ansible_skip_tags or |
215 | 262 | '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 |
219 | 266 | 'seed_containers' in ansible_run_tags) |
220 | 267 |
|
221 | 268 | - name: Setup Asset Host |
|
246 | 293 | import_playbook: ./helm_install.yml |
247 | 294 | tags: helm_install |
248 | 295 |
|
249 | | -- name: Veirfy Cert Manager hairpin Networking |
250 | | - import_playbook: ./hairpin_networking.yml |
251 | | - tags: always |
252 | | - when: use_cert_manager |
253 | | - |
254 | 296 | # since, the temp_dir are created in a different set of tasks, these directories need to be searched |
255 | 297 | - name: Clean up temporary directories |
256 | 298 | hosts: localhost |
|
0 commit comments