Skip to content

Latest commit

 

History

History
194 lines (157 loc) · 3.93 KB

README.md

File metadata and controls

194 lines (157 loc) · 3.93 KB

yumrepo

Role which helps to manage YUM repositories.

Examples

This role can be used either from a playbook (section roles):

---

- hosts: myhost
  roles:
    - role: yumrepo
      yumrepo_repos:
        myrepo1:
          name: My repo 1
          baseurl: http://myserver
          gpgcheck: 0
        myrepo2:
          name: My repo 2
          baseurl: http://myserver
          gpgcheck: 0

Or in the meta file (section dependencies):

galaxy_info:
  author: John Doe
  description: Role for App1
  license: MIT
  min_ansible_version: 1.7
  platforms:
    - name: Debian
      versions:
        - all
    - name: EL
      versions:
        - all
  categories:
    - web
dependencies:
  - role: yumrepo
    yumrepo_repos:
      myrepo2:
        name: My repo 3
        baseurl: http://myserver
        gpgcheck: 0

The role also supports managed mode which removes any repo which is not managed by this role.

---

# Example how to use the role in managed mode
- hosts: myhost
  vars:
    # This enables the managed mode
    yumrepo_manage: true

    # This prevents to delete CoreOS-Base repo file. Basically any repo file
    # which is not managed by the yumrepo role and is not listed in this variable
    # will be deleted.
    yumrepo_ignore_repo_files:
      - CentOS-Base
  roles:
    - role: yumrepo
      yumrepo_repos:
        myrepo4:
          name: My repo 4
          baseurl: http://myserver
    # When we finished with the setting of your YUM repos, we have to call the
    # role with the yumrepo_finish parameter to trigger the deletion of unmanaged
    # repos
    - role: yumrepo
      yumrepo_finish: true

If you are going to use the yumrepo across multiple plays in one playbook or in multiple playbooks, I recomend to create a shared file where you write the yumrepo_manage and the yumrepo_ignore_repo_files variables and then use it in every play the yumrepo role is used.

---

# This is the content of the shared file (e.g. vars/yumrepo.yaml)

# Enable managed mode
yumrepo_manage: true

# Ignore these repos
yumrepo_ignore_repo_files:
  - CentOS-Base
---

# This is the playbook with multiple plays using the shared file

- hosts: ~host[1-5]
  vars:
    # This is our shared file
    vars/yumrepo.yaml
  roles:
    - role: yumrepo
      yumrepo_repos:
        myrepo1:
          name: My repo 1
          baseurl: http://myserver
    - approle1

- hosts: ~host[3-5]
  vars:
    # This is our shared file
    vars/yumrepo.yaml
  roles:
    - role: yumrepo
      yumrepo_repos:
        myrepo1:
          name: My repo 2
          baseurl: http://myserver
    - approle2

# We can place the yum_finish into a separate play at the end of the playbook
- hosts: all
  vars:
    # This is our shared file
    vars/yumrepo.yaml
  roles:
    - role: yumrepo
      yumrepo_finish: true

The managed mode uses the /etc/yum.repos.d/.managed file which is generated by the role when the yumrepo_finish variable is set to true. This allows to create YUM repos across multiple roles and once all is done, it will generate the .managed file and clean the unmanaged repos.

Role variables

List of variables used by the role:

---

# If set to true, the management mode is enabled. That means that all unmanaged
# repos will be deleted). The best is to set it somewhere in a gobal variable
# file shared in all plays of the playbook.
yumrepo_manage: false

# Repository configuration
yumrepo_repos: []
# Example
#yumrepo_repos:
#  # ID of the repository
#  test:
#    # Additional parameters
#    name: Testing repo
#    baseurl: http://myserver/
#    enabled: 1
#    gpgcheck: 0
#    metadata_expire: 1

# Default list of repos files which won't be deleted during the clearing process
yumrepo_ignore_repos: []
# Example:
#yumrepo_ignore_repos:
#  - CentOS-Base

# To cleanup the temp directory and generate the .managed file
yumrepo_finish: false

License

MIT

Author

Jiri Tyr