Skip to content

Commit

Permalink
Refactoring to better handle RedHat varity related package managers
Browse files Browse the repository at this point in the history
  • Loading branch information
haxorof committed Dec 8, 2024
1 parent 8978d7f commit d8bd9f0
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 38 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## Added

- Support for DNF 5 in Fedora 41 and later [@wzzrd]
- Added `docker_install_setup_repos_dependencies` for user to disable/enable any handing of dependencies related to repo setup.

## Changed

- Improved handling between different package managers related to RedHat varity (e.g. yum, dnf, dnf5)

## [6.0.1](../../releases/tag/6.0.1) - 2024-09-07

Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ docker_disable_gpg_check: no

# Setup Docker CE apt/dnf/yum repos or assume it has already been done
docker_setup_repos: true
# Install dependencies related to setup repos (if dependencies are already installed then nothing will be changed)
docker_install_setup_repos_dependencies: yes
# Repositories required to be enabled or disabled on RHEL
# id: <id of repo>
# state: enabled || disabled
Expand Down
2 changes: 1 addition & 1 deletion tasks/install-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
name: "{{ (item is search('docker-ce')) | ternary((item + _docker_version_string | default('')), item) }}"
state: "{{ _docker_pkg_state | default('present') }}"
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"

loop: "{{ _docker_packages | default(docker_packages) }}"
register: _docker_pkg_result
Expand Down
4 changes: 2 additions & 2 deletions tasks/postinstall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
name: "epel-release"
state: present
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
register: _pkg_result
until: _pkg_result is succeeded

Expand All @@ -99,7 +99,7 @@
name: "{{ item }}"
state: present
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
loop: "{{ _docker_additional_packages_os }}"
register: _pkg_result
until: _pkg_result is succeeded
Expand Down
2 changes: 1 addition & 1 deletion tasks/setup-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name: auditd
state: present
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
register: _pkg_result
until: _pkg_result is succeeded

Expand Down
3 changes: 2 additions & 1 deletion tasks/setup-repository-Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
- name: Ensure packages are installed for repository setup
when:
- docker_network_access | bool
- docker_install_setup_repos_dependencies | bool
become: true
ansible.builtin.package:
name: "{{ item }}"
state: present
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
loop: "{{ docker_repository_related_packages[_docker_os_dist_file_varity] }}"
register: _pkg_result
until: _pkg_result is succeeded
Expand Down
11 changes: 6 additions & 5 deletions tasks/setup-repository-RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
- name: Ensure packages are installed for repository setup
when:
- docker_network_access | bool
- _docker_os_dist == "CentOS" or _docker_os_dist == "RedHat"
- docker_install_setup_repos_dependencies | bool
become: true
ansible.builtin.package:
name: "{{ item }}"
state: present
allow_unauthenticated: "{{ docker_allow_unauthenticated if ansible_pkg_mgr == 'apt' else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ docker_disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
loop: "{{ docker_repository_related_packages[_docker_os_dist_file_varity] }}"
register: _pkg_result
until: _pkg_result is succeeded
Expand All @@ -33,9 +33,10 @@
- name: Add Docker CE repository
when:
- docker_network_access | bool
- docker_install_setup_repos_dependencies | bool
become: true
ansible.builtin.get_url:
url: "{{ docker_repository_url[_docker_os_dist] | default(docker_repository_url[_docker_os_dist_file_varity]) }}"
url: "{{ docker_repository_url_rpm[_docker_os_dist] | default(docker_repository_url_rpm[_docker_os_dist_file_varity]) }}"
dest: /etc/yum.repos.d/docker-ce.repo
mode: 0644
force: yes
Expand Down Expand Up @@ -66,7 +67,7 @@

- name: Disable Docker CE repository channels
become: true
ansible.builtin.shell: "{{ docker_cmd_enable_disable_repo[_docker_os_dist] }}"
ansible.builtin.shell: "{{ docker_cmd_enable_disable_rpm_repo[ansible_pkg_mgr] }}"
loop: "{{ _docker_disable_channels }}"
changed_when: false
vars:
Expand All @@ -76,7 +77,7 @@

- name: Enable Docker CE repository channels
become: true
ansible.builtin.shell: "{{ docker_cmd_enable_disable_repo[_docker_os_dist] }}"
ansible.builtin.shell: "{{ docker_cmd_enable_disable_rpm_repo[ansible_pkg_mgr] }}"
loop: "{{ _docker_enable_channels }}"
changed_when: false
vars:
Expand Down
2 changes: 1 addition & 1 deletion tests/experimental/kata/test_katacontainers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
yum:
name: "{{ item }}"
update_cache: yes
disable_gpg_check: "{{ disable_gpg_check if ansible_pkg_mgr in ['yum', 'dnf', 'zypper'] else omit }}"
disable_gpg_check: "{{ disable_gpg_check if ansible_pkg_mgr in ['rpm', 'yum', 'dnf', 'dnf5', 'zypper'] else omit }}"
loop:
- kata-runtime
- kata-proxy
Expand Down
2 changes: 1 addition & 1 deletion tests/manual/test_network_access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
vars:
docker_network_access: false
docker_daemon_config:
icc: false
icc: false
roles:
- haxorof.docker_ce
3 changes: 0 additions & 3 deletions tests/manual/test_remove_pre_ce.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
---
- name: Determine Python interpreter
import_playbook: determine_python_interpreter.yml

- hosts: test-host
tasks:
- name: Remove Docker 1.13 and install Docker CE (RedHat)
Expand Down
45 changes: 22 additions & 23 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
---
# vars file for ansible-role-docker-ce
docker_repository_related_packages:
RedHat:
docker_repository_related_rpm_packages:
yum:
- yum-utils
dnf:
# Includes dnf config-manager
- dnf-plugins-core
dnf5:
# Includes dnf config-manager
- dnf5-plugins

docker_repository_related_packages:
RedHat: "{{ docker_repository_related_rpm_packages[ansible_pkg_mgr] }}"
Debian:
- apt-transport-https
- ca-certificates
- curl
- gnupg2
- software-properties-common

docker_repository_url:
docker_repository_url_rpm:
RedHat: https://download.docker.com/linux/rhel/docker-ce.repo
CentOS: https://download.docker.com/linux/centos/docker-ce.repo
Fedora: https://download.docker.com/linux/fedora/docker-ce.repo
Expand All @@ -20,28 +29,18 @@ docker_channels:
- nightly
- test

docker_cmd_enable_disable_repo:
AlmaLinux: >
type dnf && dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
Amazon: >
type dnf && dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
CentOS: >
type dnf && dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
Fedora: >
dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| dnf config-manager setopt docker-ce-{{item}}.enabled={{ (_item_enabled == true) | ternary('1', '0') }}
RedHat: >
type dnf && dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
Rocky: >
type dnf && dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
|| yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
docker_cmd_enable_disable_rpm_repo:
yum: yum-config-manager --{{ (_item_enabled == true) | ternary('enable', 'disable') }} docker-ce-{{ item }}
dnf: dnf config-manager --set-{{ (_item_enabled == true) | ternary('enabled', 'disabled') }} docker-ce-{{ item }}
dnf5: dnf config-manager setopt docker-ce-{{ item }}.enabled={{ (_item_enabled == true) | ternary('1', '0') }}

docker_cmd_update_rpm_repo_cache:
yum: yum makecache
dnf: dnf makecache
dnf5: dnf makecache

docker_cmd_update_repo_cache:
RedHat: type dnf && dnf makecache || yum makecache
RedHat: "{{ docker_cmd_update_rpm_repo_cache[ansible_pkg_mgr] }}"
Debian: apt-get update

docker_envs_dir:
Expand Down

0 comments on commit d8bd9f0

Please sign in to comment.