|
12 | 12 | name: kubernetes |
13 | 13 | state: present |
14 | 14 | become: true |
| 15 | + ignore_errors: true |
| 16 | + register: pip_install_result |
| 17 | + tags: always |
| 18 | +- name: Install Kubernetes Python SDK Fallback |
| 19 | + ansible.builtin.pip: |
| 20 | + name: kubernetes |
| 21 | + state: present |
| 22 | + extra_args: "--break-system-packages" |
| 23 | + become: true |
| 24 | + when: pip_install_result is failed |
| 25 | + tags: always |
| 26 | +- name: Deploy fix script for kubernetes SDK no_proxy bug |
| 27 | + ansible.builtin.copy: |
| 28 | + dest: /tmp/_fix_k8s_no_proxy.py |
| 29 | + mode: '0644' |
| 30 | + content: | |
| 31 | + import re, sys, os |
| 32 | + path = sys.argv[1] |
| 33 | + with open(path, 'r') as f: |
| 34 | + original = f.read() |
| 35 | + # Remove the duplicate self.no_proxy = None that appears after the no_proxy |
| 36 | + # env-loading block (bug introduced in kubernetes SDK >= 34.x by code generator). |
| 37 | + # Pattern: the env-loading line is followed within 3 lines by a bare self.no_proxy = None |
| 38 | + fixed = re.sub( |
| 39 | + r'(if os\.getenv\("no_proxy"\)[^\n]+\n(?:.*\n){1,3}?)(\s+self\.no_proxy = None\n)', |
| 40 | + r'\1', |
| 41 | + original |
| 42 | + ) |
| 43 | + if fixed == original: |
| 44 | + print("OK: no duplicate no_proxy line found, nothing to do") |
| 45 | + sys.exit(0) |
| 46 | + with open(path, 'w') as f: |
| 47 | + f.write(fixed) |
| 48 | + print("FIXED: removed duplicate self.no_proxy = None from " + path) |
| 49 | + sys.exit(2) |
| 50 | + become: true |
| 51 | + tags: always |
| 52 | +- name: Fix kubernetes SDK no_proxy bug (duplicate self.no_proxy = None after env-loading block) |
| 53 | + ansible.builtin.shell: | |
| 54 | + set -e |
| 55 | + KUBE_CFG=$(python3 -c "import kubernetes, os; print(os.path.join(os.path.dirname(kubernetes.__file__), 'client', 'configuration.py'))" 2>/dev/null) || exit 0 |
| 56 | + python3 /tmp/_fix_k8s_no_proxy.py "$KUBE_CFG" |
| 57 | + args: |
| 58 | + executable: /bin/bash |
| 59 | + become: true |
| 60 | + register: _no_proxy_fix |
| 61 | + changed_when: _no_proxy_fix.rc == 2 |
| 62 | + failed_when: _no_proxy_fix.rc not in [0, 2] |
| 63 | + tags: always |
| 64 | +- name: Deploy fix script for kubernetes SDK no_proxy bug |
| 65 | + ansible.builtin.copy: |
| 66 | + dest: /tmp/_fix_k8s_no_proxy.py |
| 67 | + mode: '0644' |
| 68 | + content: | |
| 69 | + import re, sys, os |
| 70 | + path = sys.argv[1] |
| 71 | + with open(path, 'r') as f: |
| 72 | + original = f.read() |
| 73 | + # Remove the duplicate self.no_proxy = None that appears after the no_proxy |
| 74 | + # env-loading block (bug introduced in kubernetes SDK >= 34.x by code generator). |
| 75 | + # Pattern: the env-loading line is followed within 3 lines by a bare self.no_proxy = None |
| 76 | + fixed = re.sub( |
| 77 | + r'(if os\.getenv\("no_proxy"\)[^\n]+\n(?:.*\n){1,3}?)(\s+self\.no_proxy = None\n)', |
| 78 | + r'\1', |
| 79 | + original |
| 80 | + ) |
| 81 | + if fixed == original: |
| 82 | + print("OK: no duplicate no_proxy line found, nothing to do") |
| 83 | + sys.exit(0) |
| 84 | + with open(path, 'w') as f: |
| 85 | + f.write(fixed) |
| 86 | + print("FIXED: removed duplicate self.no_proxy = None from " + path) |
| 87 | + sys.exit(2) |
| 88 | + become: true |
| 89 | + tags: always |
| 90 | +- name: Fix kubernetes SDK no_proxy bug (duplicate self.no_proxy = None after env-loading block) |
| 91 | + ansible.builtin.shell: | |
| 92 | + set -e |
| 93 | + KUBE_CFG=$(python3 -c "import kubernetes, os; print(os.path.join(os.path.dirname(kubernetes.__file__), 'client', 'configuration.py'))" 2>/dev/null) || exit 0 |
| 94 | + python3 /tmp/_fix_k8s_no_proxy.py "$KUBE_CFG" |
| 95 | + args: |
| 96 | + executable: /bin/bash |
| 97 | + become: true |
| 98 | + register: _no_proxy_fix |
| 99 | + changed_when: _no_proxy_fix.rc == 2 |
| 100 | + failed_when: _no_proxy_fix.rc not in [0, 2] |
15 | 101 | tags: always |
16 | 102 | - name: Install Deployment Client |
17 | 103 | ansible.builtin.shell: | |
|
0 commit comments