Instead of hardcoding the name of the package manager in
commands, use the value obtained from the inventory.
In some cases this is necessary, eg. when RPM-based
distributions are involved; for most other cases we could
get away with keepking the hardcoded names, but it's better
to be completely consistent to hopefully avoid usage of the
wrong package manager slipping with further changes.
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
---
guests/lcitool | 40 +++++++++++----------
guests/playbooks/update/tasks/base.yml | 12 +++----
guests/playbooks/update/tasks/bootstrap.yml | 16 ++-------
3 files changed, 29 insertions(+), 39 deletions(-)
diff --git a/guests/lcitool b/guests/lcitool
index 60a01fc..c179775 100755
--- a/guests/lcitool
+++ b/guests/lcitool
@@ -591,6 +591,7 @@ class Application:
facts = self._inventory.get_facts(host)
package_format = facts["package_format"]
+ package_manager = facts["package_manager"]
os_name = facts["os_name"]
os_version = facts["os_version"]
os_full = os_name + os_version
@@ -651,6 +652,7 @@ class Application:
print("FROM {}".format(facts["docker_base"]))
varmap = {}
+ varmap["package_manager"] = package_manager
varmap["pkgs"] = " \\\n
".join(sorted(set(pkgs.values())))
if package_format == "deb":
if args.cross_arch:
@@ -667,12 +669,12 @@ class Application:
sys.stdout.write(textwrap.dedent("""
RUN export DEBIAN_FRONTEND=noninteractive && \\
- apt-get update && \\
- apt-get dist-upgrade -y && \\
- apt-get install --no-install-recommends -y \\
+ {package_manager} update && \\
+ {package_manager} dist-upgrade -y && \\
+ {package_manager} install --no-install-recommends -y \\
{pkgs} && \\
- apt-get autoremove -y && \\
- apt-get autoclean -y
+ {package_manager} autoremove -y && \\
+ {package_manager} autoclean -y
""").format(**varmap))
if args.cross_arch:
# Intentionally a separate RUN command from the above
@@ -681,12 +683,12 @@ class Application:
sys.stdout.write(textwrap.dedent("""
RUN export DEBIAN_FRONTEND=noninteractive && \\
dpkg --add-architecture {cross_arch} && \\
- apt-get update && \\
- apt-get dist-upgrade -y && \\
- apt-get install --no-install-recommends -y \\
+ {package_manager} update && \\
+ {package_manager} dist-upgrade -y && \\
+ {package_manager} install --no-install-recommends -y \\
{cross_pkgs} && \\
- apt-get autoremove -y && \\
- apt-get autoclean -y
+ {package_manager} autoremove -y && \\
+ {package_manager} autoclean -y
ENV ABI "{cross_abi}"
ENV CONFIGURE_OPTS "--host={cross_abi} \\
@@ -696,18 +698,18 @@ class Application:
elif package_format == "rpm":
if os_name == "Fedora" and os_version == "Rawhide":
sys.stdout.write(textwrap.dedent("""
- RUN yum update -y --nogpgcheck fedora-gpg-keys && \\
- yum update -y && \\
- yum install -y {pkgs} && \\
- yum autoremove -y && \\
- yum clean all -y
+ RUN {package_manager} update -y --nogpgcheck fedora-gpg-keys
&& \\
+ {package_manager} update -y && \\
+ {package_manager} install -y {pkgs} && \\
+ {package_manager} autoremove -y && \\
+ {package_manager} clean all -y
""").format(**varmap))
else:
sys.stdout.write(textwrap.dedent("""
- RUN yum update -y && \\
- yum install -y {pkgs} && \\
- yum autoremove -y && \\
- yum clean all -y
+ RUN {package_manager} update -y && \\
+ {package_manager} install -y {pkgs} && \\
+ {package_manager} autoremove -y && \\
+ {package_manager} clean all -y
""").format(**varmap))
def run(self):
diff --git a/guests/playbooks/update/tasks/base.yml
b/guests/playbooks/update/tasks/base.yml
index d71d99f..59f6124 100644
--- a/guests/playbooks/update/tasks/base.yml
+++ b/guests/playbooks/update/tasks/base.yml
@@ -28,7 +28,7 @@
- os_version == 'Rawhide'
- name: Update installed packages
- command: dnf update --refresh --exclude 'kernel*' -y
+ command: '{{ package_manager }} update --refresh --exclude "kernel*"
-y'
args:
warn: no
when:
@@ -36,7 +36,7 @@
- os_version == 'Rawhide'
- name: Update installed packages
- command: dnf update --disablerepo='*'
--enablerepo=fedora-rawhide-kernel-nodebug 'kernel*' -y
+ command: '{{ package_manager }} update --disablerepo="*"
--enablerepo=fedora-rawhide-kernel-nodebug "kernel*" -y'
args:
warn: no
when:
@@ -51,19 +51,19 @@
- package_format == 'deb'
- name: Update installed packages
- shell: pkg update && pkg upgrade -y
+ shell: '{{ package_manager }} update && {{ package_manager }} upgrade
-y'
when:
- package_format == 'pkg'
- name: Clean up packages after update
- command: yum clean packages -y
+ command: '{{ package_manager }} clean packages -y'
args:
warn: no
when:
- package_format == 'rpm'
- name: Clean up packages after update
- command: yum autoremove -y
+ command: '{{ package_manager }} autoremove -y'
args:
warn: no
when:
@@ -77,7 +77,7 @@
- package_format == 'deb'
- name: Clean up packages after update
- shell: pkg clean -y && pkg autoremove -y
+ shell: '{{ package_manager }} clean -y && {{ package_manager }} autoremove
-y'
when:
- package_format == 'pkg'
diff --git a/guests/playbooks/update/tasks/bootstrap.yml
b/guests/playbooks/update/tasks/bootstrap.yml
index 44bb2c9..2e1dc42 100644
--- a/guests/playbooks/update/tasks/bootstrap.yml
+++ b/guests/playbooks/update/tasks/bootstrap.yml
@@ -1,6 +1,6 @@
---
- name: Bootstrap the pkgng package manager
- raw: env ASSUME_ALWAYS_YES=YES pkg bootstrap
+ raw: 'env ASSUME_ALWAYS_YES=YES {{ package_manager }} bootstrap'
when:
- package_format == 'pkg'
@@ -14,16 +14,4 @@
- os_version == '7'
- name: Bootstrap Ansible
- raw: 'yum install -y {{ python }}'
- when:
- - package_format == 'rpm'
-
-- name: Bootstrap Ansible
- raw: 'apt-get install -y {{ python }}'
- when:
- - package_format == 'deb'
-
-- name: Bootstrap Ansible
- raw: 'pkg install -y {{ python }}'
- when:
- - package_format == 'pkg'
+ raw: '{{ package_manager }} install -y {{ python }}'
--
2.20.1