Skip to content

Commit

Permalink
Support list for baseurl and gpgkey params in yum_repository (fixes a…
Browse files Browse the repository at this point in the history
…nsible#24948) (ansible#24967)

* Support list for baseurl and gpgkey params in yum_repository

* Adding tests
  • Loading branch information
jtyr authored and samdoran committed Aug 15, 2017
1 parent 20a35d0 commit 1b8fe94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/ansible/modules/packaging/os/yum_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
__metaclass__ = type


ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'],
'supported_by': 'core'}

ANSIBLE_METADATA = {
'metadata_version': '1.0',
'status': ['stableinterface'],
'supported_by': 'core'
}

DOCUMENTATION = '''
---
Expand Down Expand Up @@ -47,6 +48,7 @@
description:
- URL to the directory where the yum repository's 'repodata' directory
lives.
- It can also be a list of multiple URLs.
- This or the I(mirrorlist) parameter is required if I(state) is set to
C(present).
cost:
Expand Down Expand Up @@ -130,6 +132,7 @@
default: null
description:
- A URL pointing to the ASCII-armored GPG key file for the repository.
- It can also be a list of multiple URLs.
http_caching:
required: false
choices: [all, packages, none]
Expand Down Expand Up @@ -635,7 +638,7 @@ def main():
argument_spec=dict(
async=dict(type='bool'),
bandwidth=dict(),
baseurl=dict(),
baseurl=dict(type='list'),
cost=dict(),
deltarpm_metadata_percentage=dict(),
deltarpm_percentage=dict(),
Expand All @@ -647,7 +650,7 @@ def main():
file=dict(),
gpgcakey=dict(),
gpgcheck=dict(type='bool'),
gpgkey=dict(),
gpgkey=dict(type='list'),
http_caching=dict(choices=['all', 'packages', 'none']),
include=dict(),
includepkgs=dict(),
Expand Down Expand Up @@ -717,6 +720,13 @@ def main():
module.params['name'] = module.params['description']
del module.params['description']

# Change list type to string for baseurl and gpgkey
for list_param in ['baseurl', 'gpgkey']:
if (
list_param in module.params and
module.params[list_param] is not None):
module.params[list_param] = "\n".join(module.params[list_param])

# Define repo file name if it doesn't exist
if module.params['file'] is None:
module.params['file'] = module.params['repoid']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,31 @@
- name: check Idempotant
assert:
that: not epel_add.changed

- name: Test list for baseurl and gpgkey
yum_repository:
name: listtest
description: Testing list feature
baseurl:
- https://download.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
- https://download2.fedoraproject.org/pub/epel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/
gpgkey:
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-{{ ansible_distribution_major_version }}
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG2-KEY-EPEL-{{ ansible_distribution_major_version }}

- set_fact:
repofile: "{{ lookup('file', '/etc/yum.repos.d/listtest.repo') }}"

- name: Assert that lists were properly inserted
assert:
that:
- "'download.fedoraproject.org' in repofile"
- "'download2.fedoraproject.org' in repofile"
- "'RPM-GPG-KEY-EPEL' in repofile"
- "'RPM-GPG2-KEY-EPEL' in repofile"
value:

- name: Cleanup list test repo
yum_repository:
name: listtest
state: absent

0 comments on commit 1b8fe94

Please sign in to comment.