| 1 |
- meta: end_play |
| 2 |
when: ansible_os_family != 'Debian' |
| 3 |
|
| 4 |
- set_fact: |
| 5 |
python_debian: python3-debian |
| 6 |
|
| 7 |
- block: |
| 8 |
# UNINSTALL 'python3-debian' |
| 9 |
# The `deb822_repository` module has the smarts to auto-install `python3-debian`. To |
| 10 |
# test, we will first uninstall `python3-debian`. |
| 11 |
- name: check {{ python_debian }} with dpkg |
| 12 |
shell: dpkg -s {{ python_debian }} |
| 13 |
register: dpkg_result |
| 14 |
ignore_errors: true |
| 15 |
|
| 16 |
- name: uninstall {{ python_debian }} with apt |
| 17 |
apt: pkg={{ python_debian }} state=absent purge=yes |
| 18 |
register: apt_result |
| 19 |
when: dpkg_result is successful |
| 20 |
|
| 21 |
- name: check failure when python3-debian is absent |
| 22 |
deb822_repository: |
| 23 |
name: myrepo |
| 24 |
types: deb |
| 25 |
uris: "http://example.com/debian/" |
| 26 |
suites: stable |
| 27 |
components: main |
| 28 |
register: no_python3_debian |
| 29 |
ignore_errors: true |
| 30 |
|
| 31 |
- name: Assert failure with absent python3-debian |
| 32 |
assert: |
| 33 |
that: no_python3_debian.msg is contains 'python3-debian is not installed' |
| 34 |
|
| 35 |
- name: check failure when in check mode |
| 36 |
deb822_repository: |
| 37 |
name: myrepo |
| 38 |
types: deb |
| 39 |
uris: "http://example.com/debian/" |
| 40 |
suites: stable |
| 41 |
components: main |
| 42 |
register: no_python3_debian_check |
| 43 |
check_mode: true |
| 44 |
ignore_errors: true |
| 45 |
|
| 46 |
- name: assert check mode failure without python3-debian |
| 47 |
assert: |
| 48 |
that: no_python3_debian_check is failed |
| 49 |
|
| 50 |
- name: find apt path |
| 51 |
command: |
| 52 |
cmd: which apt |
| 53 |
register: aptpath |
| 54 |
|
| 55 |
- name: hide apt from ansible |
| 56 |
command: |
| 57 |
cmd: mv {{ aptpath.stdout_lines[0] }} /usr/bin/apthidden |
| 58 |
become: true |
| 59 |
|
| 60 |
- name: run deb822 with installation to check failure on nonexistent apt |
| 61 |
deb822_repository: |
| 62 |
name: myrepo |
| 63 |
types: deb |
| 64 |
uris: "http://example.com/debian/" |
| 65 |
suites: stable |
| 66 |
components: main |
| 67 |
install_python_debian: true |
| 68 |
register: failed_no_apt |
| 69 |
ignore_errors: true |
| 70 |
|
| 71 |
- name: assert failure |
| 72 |
assert: |
| 73 |
that: failed_no_apt is failed |
| 74 |
|
| 75 |
- name: move apt back |
| 76 |
command: |
| 77 |
cmd: mv /usr/bin/apthidden {{ aptpath.stdout_lines[0] }} |
| 78 |
become: true |
| 79 |
|
| 80 |
- name: break apt update |
| 81 |
copy: |
| 82 |
content: "deb [invalid syntax] http://invalid.example.com/debian stable main" |
| 83 |
dest: /etc/apt/sources.list.d/broken.list |
| 84 |
|
| 85 |
- name: run deb822 with installation to check failure on apt update |
| 86 |
deb822_repository: |
| 87 |
name: myrepo |
| 88 |
types: deb |
| 89 |
uris: "http://example.com/debian/" |
| 90 |
suites: stable |
| 91 |
components: main |
| 92 |
install_python_debian: true |
| 93 |
register: failed_apt_update |
| 94 |
ignore_errors: true |
| 95 |
|
| 96 |
- name: assert failure |
| 97 |
assert: |
| 98 |
that: failed_apt_update.msg is contains 'Failed update' |
| 99 |
|
| 100 |
- name: restore apt update |
| 101 |
file: |
| 102 |
path: /etc/apt/sources.list.d/broken.list |
| 103 |
state: absent |
| 104 |
|
| 105 |
- name: create apt preference file to break python3-debian installation |
| 106 |
copy: |
| 107 |
content: | |
| 108 |
Package: python3-debian |
| 109 |
Pin: release * |
| 110 |
Pin-Priority: -1 # Never install |
| 111 |
dest: /etc/apt/preferences.d/99-break-python3-debian.pref |
| 112 |
|
| 113 |
- name: run deb822 with installation to check failure on apt install |
| 114 |
deb822_repository: |
| 115 |
name: myrepo |
| 116 |
types: deb |
| 117 |
uris: "http://example.com/debian/" |
| 118 |
suites: stable |
| 119 |
components: main |
| 120 |
install_python_debian: true |
| 121 |
register: failed_apt_install |
| 122 |
ignore_errors: true |
| 123 |
|
| 124 |
- name: assert failure on broken install |
| 125 |
assert: |
| 126 |
that: failed_apt_install is failed |
| 127 |
|
| 128 |
- name: remove preference file |
| 129 |
file: |
| 130 |
path: /etc/apt/preferences.d/99-break-python3-debian.pref |
| 131 |
state: absent |
| 132 |
|
| 133 |
- name: run deb822 to check for python3-debian installation |
| 134 |
deb822_repository: |
| 135 |
name: myrepo |
| 136 |
types: deb |
| 137 |
uris: "http://example.com/debian/" |
| 138 |
suites: stable |
| 139 |
components: main |
| 140 |
install_python_debian: true |
| 141 |
|
| 142 |
- name: Clean up the previously added basic Debian repository |
| 143 |
deb822_repository: |
| 144 |
name: myrepo |
| 145 |
state: absent |
| 146 |
|
| 147 |
- name: install python3-debian |
| 148 |
apt: |
| 149 |
name: python3-debian |
| 150 |
state: present |
| 151 |
register: py3_deb_install |
| 152 |
|
| 153 |
- name: assert python3-debian already installed |
| 154 |
assert: |
| 155 |
that: |
| 156 |
- not py3_deb_install.changed |
| 157 |
|
| 158 |
- name: use venv to test interpreter respawn into installed environment |
| 159 |
vars: |
| 160 |
venv_dir: "{{ output_dir }}/nodeb_venv" |
| 161 |
venv_python: "{{ venv_dir }}/bin/python" |
| 162 |
block: |
| 163 |
- name: ensure venv exists |
| 164 |
pip: |
| 165 |
name: coverage |
| 166 |
virtualenv: "{{ venv_dir }}" |
| 167 |
virtualenv_command: "{{ ansible_python_interpreter }} -m venv" |
| 168 |
|
| 169 |
- name: run deb822 WITHOUT python3-debian installed to test respawning |
| 170 |
deb822_repository: |
| 171 |
name: myrepo |
| 172 |
types: deb |
| 173 |
uris: "http://example.com/debian/" |
| 174 |
suites: stable |
| 175 |
components: main |
| 176 |
register: no_python3_debian |
| 177 |
vars: |
| 178 |
ansible_python_interpreter: "{{ venv_python }}" |
| 179 |
ignore_errors: true |
| 180 |
- name: Clean up the previously added basic Debian repository |
| 181 |
deb822_repository: |
| 182 |
name: myrepo |
| 183 |
state: absent |
| 184 |
|
| 185 |
- import_tasks: test.yml |
| 186 |
- import_tasks: name_handling.yml |
| 187 |
- import_tasks: install.yml |
| 188 |
always: |
| 189 |
- name: uninstall python3-debian |
| 190 |
apt: |
| 191 |
name: python3-debian |
| 192 |
state: absent |
| 193 |
when: py3_deb_install is changed |