2014-03-14 17:04:25 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
- set_fact:
|
2016-07-03 13:18:08 +00:00
|
|
|
test_ppa_name: 'ppa:git-core/ppa'
|
|
|
|
test_ppa_filename: 'git-core'
|
|
|
|
test_ppa_spec: 'deb http://ppa.launchpad.net/git-core/ppa/ubuntu {{ansible_distribution_release}} main'
|
|
|
|
test_ppa_key: 'E1DF1F24' # http://keyserver.ubuntu.com:11371/pks/lookup?search=0xD06AAF4C11DAB86DF421421EFE6B20ECA7AD98A1&op=index
|
2014-03-14 17:04:25 +00:00
|
|
|
|
2016-09-09 01:05:44 +00:00
|
|
|
- name: show python version
|
|
|
|
debug: var=ansible_python_version
|
|
|
|
|
|
|
|
- name: use python-apt
|
|
|
|
set_fact:
|
|
|
|
python_apt: python-apt
|
2017-11-27 22:58:08 +00:00
|
|
|
when: ansible_python_version is version('3', '<')
|
2016-09-09 01:05:44 +00:00
|
|
|
|
|
|
|
- name: use python3-apt
|
|
|
|
set_fact:
|
|
|
|
python_apt: python3-apt
|
2017-11-27 22:58:08 +00:00
|
|
|
when: ansible_python_version is version('3', '>=')
|
2016-09-09 01:05:44 +00:00
|
|
|
|
2014-05-07 13:28:01 +00:00
|
|
|
# UNINSTALL 'python-apt'
|
|
|
|
# The `apt_repository` module has the smarts to auto-install `python-apt`. To
|
|
|
|
# test, we will first uninstall `python-apt`.
|
2016-09-09 01:05:44 +00:00
|
|
|
- name: check {{ python_apt }} with dpkg
|
|
|
|
shell: dpkg -s {{ python_apt }}
|
2014-05-07 13:28:01 +00:00
|
|
|
register: dpkg_result
|
|
|
|
ignore_errors: true
|
|
|
|
|
2016-09-09 01:05:44 +00:00
|
|
|
- name: uninstall {{ python_apt }} with apt
|
|
|
|
apt: pkg={{ python_apt }} state=absent purge=yes
|
2014-05-07 13:28:01 +00:00
|
|
|
register: apt_result
|
2017-11-27 22:58:08 +00:00
|
|
|
when: dpkg_result is successful
|
2014-05-07 13:28:01 +00:00
|
|
|
|
2014-03-14 17:04:25 +00:00
|
|
|
#
|
|
|
|
# TEST: apt_repository: repo=<name>
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|
|
|
|
|
|
|
|
- name: 'record apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_before
|
|
|
|
|
|
|
|
- name: 'name=<name> (expect: pass)'
|
|
|
|
apt_repository: repo='{{test_ppa_name}}' state=present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did *NOT* change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
- 'result.repo == "{{test_ppa_name}}"'
|
|
|
|
|
|
|
|
- name: 'examine apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_after
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'cache_before.stat.mtime != cache_after.stat.mtime'
|
|
|
|
|
|
|
|
- name: 'ensure ppa key is installed (expect: pass)'
|
|
|
|
apt_key: id='{{test_ppa_key}}' state=present
|
|
|
|
|
|
|
|
#
|
|
|
|
# TEST: apt_repository: repo=<name> update_cache=no
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|
|
|
|
|
|
|
|
- name: 'record apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_before
|
|
|
|
|
|
|
|
- name: 'name=<name> update_cache=no (expect: pass)'
|
|
|
|
apt_repository: repo='{{test_ppa_name}}' state=present update_cache=no
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
- 'result.repo == "{{test_ppa_name}}"'
|
|
|
|
|
|
|
|
- name: 'examine apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_after
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did *NOT* change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'cache_before.stat.mtime == cache_after.stat.mtime'
|
|
|
|
|
|
|
|
- name: 'ensure ppa key is installed (expect: pass)'
|
|
|
|
apt_key: id='{{test_ppa_key}}' state=present
|
|
|
|
|
|
|
|
#
|
|
|
|
# TEST: apt_repository: repo=<name> update_cache=yes
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|
|
|
|
|
|
|
|
- name: 'record apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_before
|
|
|
|
|
|
|
|
- name: 'name=<name> update_cache=yes (expect: pass)'
|
|
|
|
apt_repository: repo='{{test_ppa_name}}' state=present update_cache=yes
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
- 'result.repo == "{{test_ppa_name}}"'
|
|
|
|
|
|
|
|
- name: 'examine apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_after
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'cache_before.stat.mtime != cache_after.stat.mtime'
|
|
|
|
|
|
|
|
- name: 'ensure ppa key is installed (expect: pass)'
|
|
|
|
apt_key: id='{{test_ppa_key}}' state=present
|
|
|
|
|
|
|
|
#
|
|
|
|
# TEST: apt_repository: repo=<spec>
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|
|
|
|
|
|
|
|
- name: 'record apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_before
|
|
|
|
|
2019-01-15 01:16:15 +00:00
|
|
|
- name: ensure ppa key is present before adding repo that requires authentication
|
|
|
|
apt_key: keyserver=keyserver.ubuntu.com id='{{test_ppa_key}}' state=present
|
|
|
|
|
2014-03-14 17:04:25 +00:00
|
|
|
- name: 'name=<spec> (expect: pass)'
|
|
|
|
apt_repository: repo='{{test_ppa_spec}}' state=present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
- 'result.repo == "{{test_ppa_spec}}"'
|
|
|
|
|
|
|
|
- name: 'examine apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_after
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'cache_before.stat.mtime != cache_after.stat.mtime'
|
|
|
|
|
|
|
|
# When installing a repo with the spec, the key is *NOT* added
|
|
|
|
- name: 'ensure ppa key is absent (expect: pass)'
|
|
|
|
apt_key: id='{{test_ppa_key}}' state=absent
|
|
|
|
|
2015-12-16 09:37:02 +00:00
|
|
|
#
|
|
|
|
# TEST: apt_repository: repo=<spec> filename=<filename>
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|
|
|
|
|
|
|
|
- name: 'record apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_before
|
|
|
|
|
2019-01-15 01:16:15 +00:00
|
|
|
- name: ensure ppa key is present before adding repo that requires authentication
|
|
|
|
apt_key: keyserver=keyserver.ubuntu.com id='{{test_ppa_key}}' state=present
|
|
|
|
|
2015-12-16 09:37:02 +00:00
|
|
|
- name: 'name=<spec> filename=<filename> (expect: pass)'
|
|
|
|
apt_repository: repo='{{test_ppa_spec}}' filename='{{test_ppa_filename}}' state=present
|
|
|
|
register: result
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- 'result.changed'
|
|
|
|
- 'result.state == "present"'
|
|
|
|
- 'result.repo == "{{test_ppa_spec}}"'
|
|
|
|
|
|
|
|
- name: 'examine source file'
|
|
|
|
stat: path='/etc/apt/sources.list.d/{{test_ppa_filename}}.list'
|
|
|
|
register: source_file
|
|
|
|
|
|
|
|
- name: 'assert source file exists'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'source_file.stat.exists == True'
|
|
|
|
|
|
|
|
- name: 'examine apt cache mtime'
|
|
|
|
stat: path='/var/cache/apt/pkgcache.bin'
|
|
|
|
register: cache_after
|
|
|
|
|
|
|
|
- name: 'assert the apt cache did change'
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- 'cache_before.stat.mtime != cache_after.stat.mtime'
|
|
|
|
|
|
|
|
# When installing a repo with the spec, the key is *NOT* added
|
|
|
|
- name: 'ensure ppa key is absent (expect: pass)'
|
|
|
|
apt_key: id='{{test_ppa_key}}' state=absent
|
|
|
|
|
2018-03-19 14:16:43 +00:00
|
|
|
- name: Test apt_repository with a null value for repo
|
|
|
|
apt_repository:
|
|
|
|
repo:
|
|
|
|
register: result
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
- result.msg == 'Please set argument \'repo\' to a non-empty value'
|
|
|
|
|
|
|
|
- name: Test apt_repository with an empty value for repo
|
|
|
|
apt_repository:
|
|
|
|
repo: ""
|
|
|
|
register: result
|
|
|
|
ignore_errors: yes
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- result is failed
|
|
|
|
- result.msg == 'Please set argument \'repo\' to a non-empty value'
|
|
|
|
|
2014-03-14 17:04:25 +00:00
|
|
|
#
|
|
|
|
# TEARDOWN
|
|
|
|
#
|
|
|
|
- include: 'cleanup.yml'
|