From 2c53d70612d7f9f30e6a315812d95ded0417cfbb Mon Sep 17 00:00:00 2001 From: yatinkarel Date: Thu, 6 May 2021 10:16:00 +0530 Subject: [PATCH] Use dnf/yum vars based on what is available With [1] it used yum/vars but in CentOS8-Stream that is not available, so detect and use dnf or yum vars. Closes-Bug: #1927302 Change-Id: Idda53d1b68b97e5bb65314b1e07d507736932531 --- tasks/yum_common.yml | 12 ++++++++++++ tasks/yum_install_buildah.yml | 8 ++++++-- tasks/yum_update_buildah.yml | 16 ++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 tasks/yum_common.yml diff --git a/tasks/yum_common.yml b/tasks/yum_common.yml new file mode 100644 index 0000000..7fb40e2 --- /dev/null +++ b/tasks/yum_common.yml @@ -0,0 +1,12 @@ +--- +- name: Identify the primary package manager (dnf or yum) + shell: command -v dnf || command -v yum + register: pkg_mgr_output + +- name: Set fact for the used package manager binary + set_fact: + pkg_mgr: "{{ pkg_mgr_output.stdout }}" + +- name: Set fact for pkg_mgr_suffix + set_fact: + pkg_mgr_suffix: "{{ pkg_mgr.split('/')[-1] }}" diff --git a/tasks/yum_install_buildah.yml b/tasks/yum_install_buildah.yml index 56afdd0..3482cdd 100644 --- a/tasks/yum_install_buildah.yml +++ b/tasks/yum_install_buildah.yml @@ -22,6 +22,10 @@ state: file register: yum_install +- import_tasks: yum_common.yml + tags: + - always + - name: Prepare yum_install.sh script copy: src: files/yum_install.sh @@ -40,7 +44,7 @@ buildah run --volume {{ yum_install.path }}:/tmp/yum_install.sh --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d - --volume /etc/yum/vars:/etc/yum/vars + --volume /etc/{{ pkg_mgr_suffix }}/vars:/etc/{{ pkg_mgr_suffix }}/vars {% for repo in file_repos.stdout_lines %} {% if repo is exists %} --volume {{ repo }}:{{ repo }} @@ -58,7 +62,7 @@ buildah --debug run --volume {{ yum_install.path }}:/tmp/yum_install.sh --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d - --volume /etc/yum/vars:/etc/yum/vars + --volume /etc/{{ pkg_mgr_suffix }}/vars:/etc/{{ pkg_mgr_suffix }}/vars {% for repo in file_repos.stdout_lines %} {% if repo is exists %} --volume {{ repo }}:{{ repo }} diff --git a/tasks/yum_update_buildah.yml b/tasks/yum_update_buildah.yml index e4a2ae9..f2811c1 100644 --- a/tasks/yum_update_buildah.yml +++ b/tasks/yum_update_buildah.yml @@ -25,17 +25,13 @@ state: file register: yum_update -- name: Identify the primary package manager (dnf or yum) - shell: command -v dnf || command -v yum - register: pkg_mgr_output - -- name: Set fact for the used package manager binary - set_fact: - pkg_mgr: "{{ pkg_mgr_output.stdout }}" +- import_tasks: yum_common.yml + tags: + - always - name: Set fact for the used cache path set_fact: - cache_path: /var/cache/{{ pkg_mgr.split('/')[-1] }} + cache_path: /var/cache/{{ pkg_mgr_suffix }} - import_tasks: copy_rpms.yml @@ -107,7 +103,7 @@ buildah run --volume {{ yum_update.path }}:/tmp/yum_update.sh --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d - --volume /etc/yum/vars:/etc/yum/vars + --volume /etc/{{ pkg_mgr_suffix }}/vars:/etc/{{ pkg_mgr_suffix }}/vars --volume /etc/pki:/etc/pki {% if cache_volume is defined and cache_volume %} --volume {{ cache_volume }} @@ -129,7 +125,7 @@ buildah --debug run --volume {{ yum_update.path }}:/tmp/yum_update.sh --volume {{ yum_repos_dir_path }}:/etc/yum.repos.d - --volume /etc/yum/vars:/etc/yum/vars + --volume /etc/{{ pkg_mgr_suffix }}/vars:/etc/{{ pkg_mgr_suffix }}/vars --volume /etc/pki:/etc/pki {% for repo in file_repos.stdout_lines %} {% if repo is exists %}