ansible.builtin.yum_repository module – Add or remove YUM repositories
Note
This module is part of ansible-core
and included in all Ansible
installations. In most cases, you can use the short
module name
yum_repository
even without specifying the collections keyword.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.yum_repository
for easy linking to the
module documentation and to avoid conflicting with other collections that may have
the same module name.
Synopsis
Add or remove YUM repositories in RPM-based Linux distributions.
If you wish to update an existing repository definition use community.general.ini_file instead.
Parameters
Parameter |
Comments |
---|---|
If set to In ansible-core 2.11, 2.12, and 2.13 the default value is This option has been removed in RHEL 8. If you’re using one of the versions listed above, you can set this option to This parameter is deprecated as it has been removed on systems supported by ansible-core and will be removed in ansible-core 2.22. Choices:
|
|
The attributes the resulting filesystem object should have. To get supported flags look at the man page for This string should contain the attributes in the same order as the one displayed by The |
|
URL to the directory where the yum repository’s ‘repodata’ directory lives. It can also be a list of multiple URLs. This, the |
|
Relative cost of accessing this repository. Useful for weighing one repo’s packages as greater/less than any other. |
|
Whether a special flag should be added to a randomly chosen metalink/mirrorlist query each week. This allows the repository owner to estimate the number of systems consuming it. Choices:
|
|
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 This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. |
|
A human-readable string describing the repository. This option corresponds to the This parameter is only required if |
|
This tells yum whether or not use this repository. Yum default value is Choices:
|
|
Determines whether yum will allow the use of package groups for this repository. Yum default value is Choices:
|
|
List of packages to exclude from updates or installs. This should be a space separated list. Shell globs using wildcards (for example The list can also be a regular YAML array.
|
|
Choices:
|
|
File name without the |
|
A URL pointing to the ASCII-armored CA key file for the repository. This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. |
|
Tells yum whether or not it should perform a GPG signature check on packages. No default setting. If the value is not set, the system setting from Choices:
|
|
A URL pointing to the ASCII-armored GPG key file for the repository. It can also be a list of multiple URLs. |
|
Name of the group that should own the filesystem object, as would be fed to When left unspecified, it uses the current group of the current user unless you are root, in which case it can preserve the previous ownership. |
|
Determines how upstream HTTP caches are instructed to handle any HTTP downloads that Yum does.
This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. Choices:
|
|
Include external configuration file. Both, local path and URL is supported. Configuration file will be inserted at the position of the |
|
List of packages you want to only use from a repository. This should be a space separated list. Shell globs using wildcards (for example The list can also be a regular YAML array. |
|
Determines how yum resolves host names.
Choices:
|
|
This tells yum whether or not HTTP/1.1 keepalive should be used with this repository. This can improve transfer speeds by using one connection when downloading multiple files from a repository. This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. Choices:
|
|
Either This parameter is deprecated as it is only valid in the main configuration and will be removed in ansible-core 2.20. Choices:
|
|
Time (in seconds) after which the metadata will expire. Default value is 6 hours. |
|
Filter the
Note that this option does not override This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. Choices:
|
|
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 repomd.xml file to a This, the |
|
Time (in seconds) after which the mirrorlist locally cached will expire. Default value is 6 hours. This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. |
|
The permissions the resulting filesystem object should have. For those used to Giving Ansible a number without following either of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, If If Specifying |
|
Disable module RPM filtering and make all RPMs from the repository available. The default is Choices:
|
|
Unique repository ID. This option builds the section name of the repository in the repo file. This parameter is only required if |
|
Name of the user that should own the filesystem object, as would be fed to When left unspecified, it uses the current user unless you are root, in which case it can preserve the previous ownership. Specifying a numeric username will be assumed to be a user ID and not a username. Avoid numeric usernames to avoid this confusion. |
|
Password to use with the username for basic authentication. |
|
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 packages from updates from other repositories. This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. Choices:
|
|
URL to the proxy server that yum should use. Set to |
|
Password for this proxy. |
|
Username to use for proxy. |
|
This tells yum whether or not it should perform a GPG signature check on the repodata from this repository. Choices:
|
|
Directory where the Default: |
|
Set the number of times any attempt to retrieve a file should retry before returning an error. Setting this to |
|
Enables support for S3 repositories. This option only works if the YUM S3 plugin is installed. Choices:
|
|
The level part of the SELinux filesystem object context. This is the MLS/MCS attribute, sometimes known as the When set to |
|
The role part of the SELinux filesystem object context. When set to |
|
The type part of the SELinux filesystem object context. When set to |
|
The user part of the SELinux filesystem object context. By default it uses the When set to |
|
If set to Choices:
|
|
Whether yum should check the permissions on the paths for the certificates on the repository (both remote and local). If we can’t read any of the files then yum will force This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. Choices:
|
|
Path to the directory containing the databases of the certificate authorities yum should use to verify SSL certificates. |
|
Path to the SSL client certificate yum should use to connect to repos/remote sites. |
|
Path to the SSL client key yum should use to connect to repos/remote sites. |
|
Defines whether yum should verify SSL certificates/hosts at all. Choices:
|
|
State of the repo file. Choices:
|
|
Enable bandwidth throttling for downloads. This option can be expressed as a absolute data rate in bytes/sec. An SI prefix (k, M or G) may be appended to the bandwidth value. |
|
Number of seconds to wait for a connection before timing out. |
|
When a repository id is displayed, append these yum variables to the string if they are used in the This parameter is deprecated as it has no effect with dnf as an underlying package manager and will be removed in ansible-core 2.22. |
|
Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target filesystem object. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target filesystem objects, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted filesystem objects, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating filesystem objects when atomic operations fail (however, it doesn’t force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. Choices:
|
|
Username to use for basic authentication to a repo or really any url. |
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: full |
Can run in check_mode and return changed status prediction without modifying target, if not supported the action will be skipped. |
|
Support: full |
Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode |
|
Platform: rhel |
Target OS/families that can be operated against |
Notes
Note
All comments will be removed if modifying an existing repo file.
Section order is preserved in an existing repo file.
Parameters in a section are ordered alphabetically in an existing repo file.
The repo file will be automatically deleted if it contains no repository.
When removing a repository, beware that the metadata cache may still remain on disk until you run
yum clean all
. Use a notification handler for this.The
params
parameter was removed in Ansible 2.5 due to circumventing Ansible’s parameter handling
Examples
- name: Add repository
ansible.builtin.yum_repository:
name: epel
description: EPEL YUM repo
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
- name: Add multiple repositories into the same file (1/2)
ansible.builtin.yum_repository:
name: epel
description: EPEL YUM repo
file: external_repos
baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
gpgcheck: no
- name: Add multiple repositories into the same file (2/2)
ansible.builtin.yum_repository:
name: rpmforge
description: RPMforge YUM repo
file: external_repos
baseurl: http://apt.sw.be/redhat/el7/en/$basearch/rpmforge
mirrorlist: http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
enabled: no
# Handler showing how to clean yum metadata cache
- name: yum-clean-metadata
ansible.builtin.command: yum clean metadata
# Example removing a repository and cleaning up metadata cache
- name: Remove repository (and clean up left-over metadata)
ansible.builtin.yum_repository:
name: epel
state: absent
notify: yum-clean-metadata
- name: Remove repository from a specific repo file
ansible.builtin.yum_repository:
name: epel
file: external_repos
state: absent
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
repository name Returned: success Sample: |
|
state of the target, after execution Returned: success Sample: |