tripleo-validations/roles/repos/tasks/main.yml
Cédric Jeanneret fa974b9fb9 Correct "repos" validation and adds Molecule tests
The way `yum repolist' works isn't consistent on CentOS-7 and Fedora. On
the first, it does fail on a broken repository, spitting an error on
STDERR and exiting with 1.

On Fedora, it sadly just ignores the failing repository with a single
line, and exits with 0.

This patch intends to make the validation more resilient, and adds
Molecule testing in order to ensure it's actually working as expected.

Change-Id: Ib46f5993eeac6ec39a603da3b8e943c960d7c52d
2019-07-25 15:26:34 +02:00

30 lines
829 B
YAML

---
- name: List repositories
become: True
shell: |
{{ ansible_pkg_mgr }} repolist enabled -v 2>&1 || exit 0
args:
warn: no
changed_when: False
register: repositories
- name: Fail if we detect error in repolist output
fail:
msg: |
One or more repositories are either broken or unreachable. Please correct.
when:
repositories.stdout is regex('(cannot|could not|failure)', ignorecase=True)
- name: Find repository IDs
changed_when: False
shell: 'echo "{{ repositories.stdout }}" | grep Repo-id | sed "s/Repo-id.*://" | tr -d " "'
register: repository_ids
- name: Check if there are any unwanted repositories enabled
fail:
msg: Found unwanted repository {{ item.0 }} enabled
when: item.0 == item.1
with_nested:
- [ 'epel/x86_64' ]
- "{{ repository_ids.stdout_lines }}"