Merge pull request #1772 from jtyr/jtyr-yumrepo_new_params

Adding more options to the yum_repository module
reviewable/pr18780/r1
Toshio Kuratomi 9 years ago
commit 95d54004af

@ -1,7 +1,7 @@
#!/usr/bin/python #!/usr/bin/python
# encoding: utf-8 # encoding: utf-8
# (c) 2015, Jiri Tyr <jiri.tyr@gmail.com> # (c) 2015-2016, Jiri Tyr <jiri.tyr@gmail.com>
# #
# This file is part of Ansible # This file is part of Ansible
# #
@ -33,6 +33,13 @@ description:
- Add or remove YUM repositories in RPM-based Linux distributions. - Add or remove YUM repositories in RPM-based Linux distributions.
options: options:
async:
required: false
choices: ['yes', 'no']
default: 'yes'
description:
- If set to C(yes) Yum will download packages and metadata from this
repo in parallel, if possible.
bandwidth: bandwidth:
required: false required: false
default: 0 default: 0
@ -45,22 +52,40 @@ options:
throttling). throttling).
baseurl: baseurl:
required: false required: false
default: None default: null
description: description:
- URL to the directory where the yum repository's 'repodata' directory - URL to the directory where the yum repository's 'repodata' directory
lives. lives.
- This or the I(mirrorlist) parameter is required. - This or the I(mirrorlist) parameter is required if I(state) is set to
C(present).
cost: cost:
required: false required: false
default: 1000 default: 1000
description: description:
- Relative cost of accessing this repository. Useful for weighing one - Relative cost of accessing this repository. Useful for weighing one
repo's packages as greater/less than any other. repo's packages as greater/less than any other.
deltarpm_metadata_percentage:
required: false
default: 100
description: description:
- When the relative size of deltarpm metadata vs pkgs is larger than
this, deltarpm metadata is not downloaded from the repo. Note that you
can give values over C(100), so C(200) means that the metadata is
required to be half the size of the packages. Use C(0) to turn off
this check, and always download metadata.
deltarpm_percentage:
required: false required: false
default: None default: 75
description:
- When the relative size of delta vs pkg is larger than this, delta is
not used. Use C(0) to turn off delta rpm processing. Local repositories
(with file:// I(baseurl)) have delta rpms turned off by default.
description:
required: false
default: null
description: description:
- A human readable string describing the repository. - A human readable string describing the repository.
- This parameter is only required if I(state) is set to C(present).
enabled: enabled:
required: false required: false
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -76,7 +101,7 @@ options:
repository. repository.
exclude: exclude:
required: false required: false
default: None default: null
description: description:
- List of packages to exclude from updates or installs. This should be a - List of packages to exclude from updates or installs. This should be a
space separated list. Shell globs using wildcards (eg. C(*) and C(?)) space separated list. Shell globs using wildcards (eg. C(*) and C(?))
@ -90,16 +115,16 @@ options:
- C(roundrobin) randomly selects a URL out of the list of URLs to start - C(roundrobin) randomly selects a URL out of the list of URLs to start
with and proceeds through each of them as it encounters a failure with and proceeds through each of them as it encounters a failure
contacting the host. contacting the host.
- C(priority) starts from the first baseurl listed and reads through them - C(priority) starts from the first I(baseurl) listed and reads through
sequentially. them sequentially.
file: file:
required: false required: false
default: None default: null
description: description:
- File to use to save the repo in. Defaults to the value of I(name). - File to use to save the repo in. Defaults to the value of I(name).
gpgcakey: gpgcakey:
required: false required: false
default: None default: null
description: description:
- A URL pointing to the ASCII-armored CA key file for the repository. - A URL pointing to the ASCII-armored CA key file for the repository.
gpgcheck: gpgcheck:
@ -111,7 +136,7 @@ options:
packages. packages.
gpgkey: gpgkey:
required: false required: false
default: None default: null
description: description:
- A URL pointing to the ASCII-armored GPG key file for the repository. - A URL pointing to the ASCII-armored GPG key file for the repository.
http_caching: http_caching:
@ -125,15 +150,31 @@ options:
- C(packages) means that only RPM package downloads should be cached (but - C(packages) means that only RPM package downloads should be cached (but
not repository metadata downloads). not repository metadata downloads).
- C(none) means that no HTTP downloads should be cached. - C(none) means that no HTTP downloads should be cached.
include:
required: false
default: null
description:
- Include external configuration file. Both, local path and URL is
supported. Configuration file will be inserted at the position of the
I(include=) line. Included files may contain further include lines.
Yum will abort with an error if an inclusion loop is detected.
includepkgs: includepkgs:
required: false required: false
default: None default: null
description: description:
- List of packages you want to only use from a repository. This should be - List of packages you want to only use from a repository. This should be
a space separated list. Shell globs using wildcards (eg. C(*) and C(?)) a space separated list. Shell globs using wildcards (eg. C(*) and C(?))
are allowed. Substitution variables (e.g. C($releasever)) are honored are allowed. Substitution variables (e.g. C($releasever)) are honored
here. here.
- The list can also be a regular YAML array. - The list can also be a regular YAML array.
ip_resolve:
required: false
choices: [4, 6, IPv4, IPv6, whatever]
default: whatever
description:
- Determines how yum resolves host names.
- C(4) or C(IPv4) - resolve to IPv4 addresses only.
- C(6) or C(IPv6) - resolve to IPv6 addresses only.
keepalive: keepalive:
required: false required: false
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -142,25 +183,54 @@ options:
- This tells yum whether or not HTTP/1.1 keepalive should be used with - This tells yum whether or not HTTP/1.1 keepalive should be used with
this repository. This can improve transfer speeds by using one this repository. This can improve transfer speeds by using one
connection when downloading multiple files from a repository. connection when downloading multiple files from a repository.
keepcache:
required: false
choices: ['0', '1']
default: '1'
description:
- Either C(1) or C(0). Determines whether or not yum keeps the cache of
headers and packages after successful installation.
metadata_expire: metadata_expire:
required: false required: false
default: 21600 default: 21600
description: description:
- Time (in seconds) after which the metadata will expire. - Time (in seconds) after which the metadata will expire.
- Default value is 6 hours. - Default value is 6 hours.
metadata_expire_filter:
required: false
choices: [never, 'read-only:past', 'read-only:present', 'read-only:future']
default: 'read-only:present'
description:
- Filter the I(metadata_expire) time, allowing a trade of speed for
accuracy if a command doesn't require it. Each yum command can specify
that it requires a certain level of timeliness quality from the remote
repos. from "I'm about to install/upgrade, so this better be current"
to "Anything that's available is good enough".
- C(never) - Nothing is filtered, always obey I(metadata_expire).
- C(read-only:past) - Commands that only care about past information are
filtered from metadata expiring. Eg. I(yum history) info (if history
needs to lookup anything about a previous transaction, then by
definition the remote package was available in the past).
- C(read-only:present) - Commands that are balanced between past and
future. Eg. I(yum list yum).
- C(read-only:future) - Commands that are likely to result in running
other commands which will require the latest metadata. Eg.
I(yum check-update).
- Note that this option does not override "yum clean expire-cache".
metalink: metalink:
required: false required: false
default: None default: null
description: description:
- Specifies a URL to a metalink file for the repomd.xml, a list of - Specifies a URL to a metalink file for the repomd.xml, a list of
mirrors for the entire repository are generated by converting the mirrors for the entire repository are generated by converting the
mirrors for the repomd.xml file to a baseurl. mirrors for the repomd.xml file to a I(baseurl).
mirrorlist: mirrorlist:
required: false required: false
default: None default: null
description: description:
- Specifies a URL to a file containing a list of baseurls. - Specifies a URL to a file containing a list of baseurls.
- This or the I(baseurl) parameter is required. - This or the I(baseurl) parameter is required if I(state) is set to
C(present).
mirrorlist_expire: mirrorlist_expire:
required: false required: false
default: 21600 default: 21600
@ -172,17 +242,26 @@ options:
required: true required: true
description: description:
- Unique repository ID. - Unique repository ID.
- This parameter is only required if I(state) is set to C(present) or
C(absent).
params: params:
required: false required: false
default: None default: null
description: description:
- Option used to allow the user to overwrite any of the other options. To - Option used to allow the user to overwrite any of the other options.
remove an option, set the value of the option to C(null). To remove an option, set the value of the option to C(null).
password: password:
required: false required: false
default: None default: null
description: description:
- Password to use with the username for basic authentication. - Password to use with the username for basic authentication.
priority:
required: false
default: 99
description:
- Enforce ordered protection of repositories. The value is an integer
from 1 to 99.
- This option only works if the YUM Priorities plugin is installed.
protect: protect:
required: false required: false
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -191,17 +270,17 @@ options:
- Protect packages from updates from other repositories. - Protect packages from updates from other repositories.
proxy: proxy:
required: false required: false
default: None default: null
description: description:
- URL to the proxy server that yum should use. - URL to the proxy server that yum should use.
proxy_password: proxy_password:
required: false required: false
default: None default: null
description: description:
- Username to use for proxy. - Username to use for proxy.
proxy_username: proxy_username:
required: false required: false
default: None default: null
description: description:
- Password for this proxy. - Password for this proxy.
repo_gpgcheck: repo_gpgcheck:
@ -222,6 +301,13 @@ options:
description: description:
- Set the number of times any attempt to retrieve a file should retry - Set the number of times any attempt to retrieve a file should retry
before returning an error. Setting this to C(0) makes yum try forever. before returning an error. Setting this to C(0) makes yum try forever.
s3_enabled:
required: false
choices: ['yes', 'no']
default: 'no'
description:
- Enables support for S3 repositories.
- This option only works if the YUM S3 plugin is installed.
skip_if_unavailable: skip_if_unavailable:
required: false required: false
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -230,12 +316,6 @@ options:
- If set to C(yes) yum will continue running if this repository cannot be - If set to C(yes) yum will continue running if this repository cannot be
contacted for any reason. This should be set carefully as all repos are contacted for any reason. This should be set carefully as all repos are
consulted for any given command. consulted for any given command.
sslcacert:
required: false
default: None
description:
- Path to the directory containing the databases of the certificate
authorities yum should use to verify SSL certificates.
ssl_check_cert_permissions: ssl_check_cert_permissions:
required: false required: false
choices: ['yes', 'no'] choices: ['yes', 'no']
@ -244,18 +324,24 @@ options:
- Whether yum should check the permissions on the paths for the - Whether yum should check the permissions on the paths for the
certificates on the repository (both remote and local). certificates on the repository (both remote and local).
- If we can't read any of the files then yum will force - If we can't read any of the files then yum will force
I(skip_if_unavailable) to be true. This is most useful for non-root I(skip_if_unavailable) to be C(yes). This is most useful for non-root
processes which use yum on repos that have client cert files which are processes which use yum on repos that have client cert files which are
readable only by root. readable only by root.
sslcacert:
required: false
default: null
description:
- Path to the directory containing the databases of the certificate
authorities yum should use to verify SSL certificates.
sslclientcert: sslclientcert:
required: false required: false
default: None default: null
description: description:
- Path to the SSL client certificate yum should use to connect to - Path to the SSL client certificate yum should use to connect to
repos/remote sites. repos/remote sites.
sslclientkey: sslclientkey:
required: false required: false
default: None default: null
description: description:
- Path to the SSL client key yum should use to connect to repos/remote - Path to the SSL client key yum should use to connect to repos/remote
sites. sites.
@ -270,10 +356,10 @@ options:
choices: [absent, present] choices: [absent, present]
default: present default: present
description: description:
- A source string state. - State of the repo file.
throttle: throttle:
required: false required: false
default: None default: null
description: description:
- Enable bandwidth throttling for downloads. - Enable bandwidth throttling for downloads.
- This option can be expressed as a absolute data rate in bytes/sec. An - This option can be expressed as a absolute data rate in bytes/sec. An
@ -283,9 +369,16 @@ options:
default: 30 default: 30
description: description:
- Number of seconds to wait for a connection before timing out. - Number of seconds to wait for a connection before timing out.
ui_repoid_vars:
required: false
default: releasever basearch
description:
- When a repository id is displayed, append these yum variables to the
string if they are used in the I(baseurl)/etc. Variables are appended
in the order listed (and found).
username: username:
required: false required: false
default: None default: null
description: description:
- Username to use for basic authentication to a repo or really any url. - Username to use for basic authentication to a repo or really any url.
@ -377,14 +470,51 @@ class YumRepo(object):
# List of parameters which will be allowed in the repo file output # List of parameters which will be allowed in the repo file output
allowed_params = [ allowed_params = [
'bandwidth', 'baseurl', 'cost', 'enabled', 'enablegroups', 'exclude', 'async',
'failovermethod', 'gpgcakey', 'gpgcheck', 'gpgkey', 'http_caching', 'bandwidth',
'includepkgs', 'keepalive', 'metadata_expire', 'metalink', 'baseurl',
'mirrorlist', 'mirrorlist_expire', 'name', 'password', 'protect', 'cost',
'proxy', 'proxy_password', 'proxy_username', 'repo_gpgcheck', 'deltarpm_metadata_percentage',
'retries', 'skip_if_unavailable', 'sslcacert', 'deltarpm_percentage',
'ssl_check_cert_permissions', 'sslclientcert', 'sslclientkey', 'enabled',
'sslverify', 'throttle', 'timeout', 'username'] 'enablegroups',
'exclude',
'failovermethod',
'gpgcakey',
'gpgcheck',
'gpgkey',
'http_caching',
'ignore_repo_files',
'include',
'includepkgs',
'ip_resolve',
'keepalive',
'keepcache',
'metadata_expire',
'metadata_expire_filter',
'metalink',
'mirrorlist',
'mirrorlist_expire',
'name',
'password',
'priority',
'protect',
'proxy',
'proxy_password',
'proxy_username',
'repo_gpgcheck',
'retries',
's3_enabled',
'skip_if_unavailable',
'sslcacert',
'ssl_check_cert_permissions',
'sslclientcert',
'sslclientkey',
'sslverify',
'throttle',
'timeout',
'ui_repoid_vars',
'username']
# List of parameters which can be a list # List of parameters which can be a list
list_params = ['exclude', 'includepkgs'] list_params = ['exclude', 'includepkgs']
@ -401,15 +531,11 @@ class YumRepo(object):
repos_dir = self.params['reposdir'] repos_dir = self.params['reposdir']
if not os.path.isdir(repos_dir): if not os.path.isdir(repos_dir):
self.module.fail_json( self.module.fail_json(
msg='Repo directory "%s" does not exist.' % repos_dir) msg="Repo directory '%s' does not exist." % repos_dir)
# Get the given or the default repo file name
repo_file = self.params['repoid']
if self.params['file'] is not None:
repo_file = self.params['file']
# Set dest; also used to set dest parameter for the FS attributes # Set dest; also used to set dest parameter for the FS attributes
self.params['dest'] = os.path.join(repos_dir, "%s.repo" % repo_file) self.params['dest'] = os.path.join(
repos_dir, "%s.repo" % self.params['file'])
# Read the repo file if it exists # Read the repo file if it exists
if os.path.isfile(self.params['dest']): if os.path.isfile(self.params['dest']):
@ -449,28 +575,29 @@ class YumRepo(object):
# Write data into the file # Write data into the file
try: try:
fd = open(self.params['dest'], 'wb') fd = open(self.params['dest'], 'wb')
except IOError: except IOError, e:
self.module.fail_json( self.module.fail_json(
msg='Cannot open repo file %s.' % msg="Cannot open repo file %s." % self.params['dest'],
self.params['dest']) details=str(e))
try:
try:
self.repofile.write(fd) self.repofile.write(fd)
except Error:
self.module.fail_json( try:
msg='Cannot write repo file %s.' %
self.params['dest'])
finally:
fd.close() fd.close()
except IOError, e:
self.module.fail_json(
msg="Cannot write repo file %s." % self.params['dest'],
details=str(e))
else: else:
# Remove the file if there are not repos # Remove the file if there are not repos
try: try:
os.remove(self.params['dest']) os.remove(self.params['dest'])
except OSError: except OSError, e:
self.module.fail_json( self.module.fail_json(
msg='Cannot remove empty repo file %s.' % msg=(
self.params['dest']) "Cannot remove empty repo file %s." %
self.params['dest']),
details=str(e))
def remove(self): def remove(self):
# Remove section if exists # Remove section if exists
@ -496,9 +623,12 @@ def main():
# Module settings # Module settings
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
async=dict(type='bool'),
bandwidth=dict(), bandwidth=dict(),
baseurl=dict(), baseurl=dict(),
cost=dict(), cost=dict(),
deltarpm_metadata_percentage=dict(),
deltarpm_percentage=dict(),
description=dict(), description=dict(),
enabled=dict(type='bool'), enabled=dict(type='bool'),
enablegroups=dict(type='bool'), enablegroups=dict(type='bool'),
@ -509,15 +639,26 @@ def main():
gpgcheck=dict(type='bool'), gpgcheck=dict(type='bool'),
gpgkey=dict(), gpgkey=dict(),
http_caching=dict(choices=['all', 'packages', 'none']), http_caching=dict(choices=['all', 'packages', 'none']),
ignore_repo_files=dict(default=[]),
include=dict(),
includepkgs=dict(), includepkgs=dict(),
ip_resolve=dict(choices=['4', '6', 'IPv4', 'IPv6', 'whatever']),
keepalive=dict(type='bool'), keepalive=dict(type='bool'),
keepcache=dict(choices=['0', '1']),
metadata_expire=dict(), metadata_expire=dict(),
metadata_expire_filter=dict(
choices=[
'never',
'read-only:past',
'read-only:present',
'read-only:future']),
metalink=dict(), metalink=dict(),
mirrorlist=dict(), mirrorlist=dict(),
mirrorlist_expire=dict(), mirrorlist_expire=dict(),
name=dict(required=True), name=dict(required=True),
params=dict(), params=dict(),
password=dict(no_log=True), password=dict(no_log=True),
priority=dict(),
protect=dict(type='bool'), protect=dict(type='bool'),
proxy=dict(), proxy=dict(),
proxy_password=dict(no_log=True), proxy_password=dict(no_log=True),
@ -525,6 +666,7 @@ def main():
repo_gpgcheck=dict(type='bool'), repo_gpgcheck=dict(type='bool'),
reposdir=dict(default='/etc/yum.repos.d'), reposdir=dict(default='/etc/yum.repos.d'),
retries=dict(), retries=dict(),
s3_enabled=dict(type='bool'),
skip_if_unavailable=dict(type='bool'), skip_if_unavailable=dict(type='bool'),
sslcacert=dict(), sslcacert=dict(),
ssl_check_cert_permissions=dict(type='bool'), ssl_check_cert_permissions=dict(type='bool'),
@ -534,6 +676,7 @@ def main():
state=dict(choices=['present', 'absent'], default='present'), state=dict(choices=['present', 'absent'], default='present'),
throttle=dict(), throttle=dict(),
timeout=dict(), timeout=dict(),
ui_repoid_vars=dict(),
username=dict(), username=dict(),
), ),
add_file_common_args=True, add_file_common_args=True,
@ -549,11 +692,26 @@ def main():
name = module.params['name'] name = module.params['name']
state = module.params['state'] state = module.params['state']
# Check if required parameters are present
if state == 'present':
if (
module.params['baseurl'] is None and
module.params['mirrorlist'] is None):
module.fail_json(
msg="Parameter 'baseurl' or 'mirrorlist' is required.")
if module.params['description'] is None:
module.fail_json(
msg="Parameter 'description' is required.")
# Rename "name" and "description" to ensure correct key sorting # Rename "name" and "description" to ensure correct key sorting
module.params['repoid'] = module.params['name'] module.params['repoid'] = module.params['name']
module.params['name'] = module.params['description'] module.params['name'] = module.params['description']
del module.params['description'] del module.params['description']
# Define repo file name if it doesn't exist
if module.params['file'] is None:
module.params['file'] = module.params['repoid']
# Instantiate the YumRepo object # Instantiate the YumRepo object
yumrepo = YumRepo(module) yumrepo = YumRepo(module)

Loading…
Cancel
Save