Ansible and Python both support actual dictionaries, so make use of them in the inventory instead of emulating them by using variable names sharing the same prefix. Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> --- guests/host_vars/libvirt-centos-7/main.yml | 5 +- guests/host_vars/libvirt-centos-8/main.yml | 5 +- guests/host_vars/libvirt-debian-10/main.yml | 5 +- guests/host_vars/libvirt-debian-9/main.yml | 5 +- guests/host_vars/libvirt-debian-sid/main.yml | 5 +- guests/host_vars/libvirt-fedora-30/main.yml | 5 +- guests/host_vars/libvirt-fedora-31/main.yml | 5 +- .../host_vars/libvirt-fedora-rawhide/main.yml | 5 +- guests/host_vars/libvirt-freebsd-11/main.yml | 5 +- guests/host_vars/libvirt-freebsd-12/main.yml | 5 +- .../libvirt-freebsd-current/main.yml | 5 +- .../host_vars/libvirt-opensuse-151/main.yml | 5 +- guests/host_vars/libvirt-ubuntu-1604/main.yml | 5 +- guests/host_vars/libvirt-ubuntu-1804/main.yml | 5 +- guests/lcitool | 79 ++++++++----------- guests/playbooks/update/tasks/base.yml | 28 +++---- guests/playbooks/update/tasks/bootstrap.yml | 6 +- guests/playbooks/update/tasks/packages.yml | 8 +- guests/playbooks/update/tasks/services.yml | 2 +- guests/playbooks/update/templates/bashrc.j2 | 6 +- 20 files changed, 101 insertions(+), 98 deletions(-) diff --git a/guests/host_vars/libvirt-centos-7/main.yml b/guests/host_vars/libvirt-centos-7/main.yml index ac40c7c..66cb113 100644 --- a/guests/host_vars/libvirt-centos-7/main.yml +++ b/guests/host_vars/libvirt-centos-7/main.yml @@ -19,8 +19,9 @@ os: name: 'CentOS' version: '7' -package_format: 'rpm' -package_manager: 'yum' +packaging: + format: rpm + command: yum bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-centos-8/main.yml b/guests/host_vars/libvirt-centos-8/main.yml index 77ba6b1..e48c1ff 100644 --- a/guests/host_vars/libvirt-centos-8/main.yml +++ b/guests/host_vars/libvirt-centos-8/main.yml @@ -19,8 +19,9 @@ os: name: 'CentOS' version: '8' -package_format: 'rpm' -package_manager: 'dnf' +packaging: + format: 'rpm' + command: 'dnf' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-debian-10/main.yml b/guests/host_vars/libvirt-debian-10/main.yml index cb859d1..da30dac 100644 --- a/guests/host_vars/libvirt-debian-10/main.yml +++ b/guests/host_vars/libvirt-debian-10/main.yml @@ -21,8 +21,9 @@ os: name: 'Debian' version: '10' -package_format: 'deb' -package_manager: 'apt-get' +packaging: + format: 'deb' + command: 'apt-get' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-debian-9/main.yml b/guests/host_vars/libvirt-debian-9/main.yml index c9b739d..82ed8b2 100644 --- a/guests/host_vars/libvirt-debian-9/main.yml +++ b/guests/host_vars/libvirt-debian-9/main.yml @@ -21,8 +21,9 @@ os: name: 'Debian' version: '9' -package_format: 'deb' -package_manager: 'apt-get' +packaging: + format: 'deb' + command: 'apt-get' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-debian-sid/main.yml b/guests/host_vars/libvirt-debian-sid/main.yml index 6e1adda..f0c0c8e 100644 --- a/guests/host_vars/libvirt-debian-sid/main.yml +++ b/guests/host_vars/libvirt-debian-sid/main.yml @@ -21,8 +21,9 @@ os: name: 'Debian' version: 'Sid' -package_format: 'deb' -package_manager: 'apt-get' +packaging: + format: 'deb' + command: 'apt-get' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-fedora-30/main.yml b/guests/host_vars/libvirt-fedora-30/main.yml index 2a317c3..d9e539e 100644 --- a/guests/host_vars/libvirt-fedora-30/main.yml +++ b/guests/host_vars/libvirt-fedora-30/main.yml @@ -34,8 +34,9 @@ os: name: 'Fedora' version: '30' -package_format: 'rpm' -package_manager: 'dnf' +packaging: + format: 'rpm' + command: 'dnf' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-fedora-31/main.yml b/guests/host_vars/libvirt-fedora-31/main.yml index ade64ed..b884e7f 100644 --- a/guests/host_vars/libvirt-fedora-31/main.yml +++ b/guests/host_vars/libvirt-fedora-31/main.yml @@ -22,8 +22,9 @@ os: name: 'Fedora' version: '31' -package_format: 'rpm' -package_manager: 'dnf' +packaging: + format: 'rpm' + command: 'dnf' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-fedora-rawhide/main.yml b/guests/host_vars/libvirt-fedora-rawhide/main.yml index b11e37c..732b988 100644 --- a/guests/host_vars/libvirt-fedora-rawhide/main.yml +++ b/guests/host_vars/libvirt-fedora-rawhide/main.yml @@ -22,8 +22,9 @@ os: name: 'Fedora' version: 'Rawhide' -package_format: 'rpm' -package_manager: 'dnf' +packaging: + format: 'rpm' + command: 'dnf' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-freebsd-11/main.yml b/guests/host_vars/libvirt-freebsd-11/main.yml index b01c62b..e22b688 100644 --- a/guests/host_vars/libvirt-freebsd-11/main.yml +++ b/guests/host_vars/libvirt-freebsd-11/main.yml @@ -20,8 +20,9 @@ os: name: 'FreeBSD' version: '11' -package_format: 'pkg' -package_manager: 'pkg' +packaging: + format: 'pkg' + command: 'pkg' bash: /usr/local/bin/bash cc: /usr/bin/clang diff --git a/guests/host_vars/libvirt-freebsd-12/main.yml b/guests/host_vars/libvirt-freebsd-12/main.yml index 5da1446..1fa718e 100644 --- a/guests/host_vars/libvirt-freebsd-12/main.yml +++ b/guests/host_vars/libvirt-freebsd-12/main.yml @@ -20,8 +20,9 @@ os: name: 'FreeBSD' version: '12' -package_format: 'pkg' -package_manager: 'pkg' +packaging: + format: 'pkg' + command: 'pkg' bash: /usr/local/bin/bash cc: /usr/bin/clang diff --git a/guests/host_vars/libvirt-freebsd-current/main.yml b/guests/host_vars/libvirt-freebsd-current/main.yml index 03e3615..706abc8 100644 --- a/guests/host_vars/libvirt-freebsd-current/main.yml +++ b/guests/host_vars/libvirt-freebsd-current/main.yml @@ -20,8 +20,9 @@ os: name: 'FreeBSD' version: 'Current' -package_format: 'pkg' -package_manager: 'pkg' +packaging: + format: 'pkg' + command: 'pkg' bash: /usr/local/bin/bash cc: /usr/bin/clang diff --git a/guests/host_vars/libvirt-opensuse-151/main.yml b/guests/host_vars/libvirt-opensuse-151/main.yml index 4050817..b80a497 100644 --- a/guests/host_vars/libvirt-opensuse-151/main.yml +++ b/guests/host_vars/libvirt-opensuse-151/main.yml @@ -20,8 +20,9 @@ os: name: 'OpenSUSE' version: '151' -package_format: 'rpm' -package_manager: 'zypper' +packaging: + format: 'rpm' + command: 'zypper' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-ubuntu-1604/main.yml b/guests/host_vars/libvirt-ubuntu-1604/main.yml index 1e7ab72..2d99e3a 100644 --- a/guests/host_vars/libvirt-ubuntu-1604/main.yml +++ b/guests/host_vars/libvirt-ubuntu-1604/main.yml @@ -20,8 +20,9 @@ os: name: 'Ubuntu' version: '1604' -package_format: 'deb' -package_manager: 'apt-get' +packaging: + format: 'deb' + command: 'apt-get' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/host_vars/libvirt-ubuntu-1804/main.yml b/guests/host_vars/libvirt-ubuntu-1804/main.yml index 73e4842..4c63b35 100644 --- a/guests/host_vars/libvirt-ubuntu-1804/main.yml +++ b/guests/host_vars/libvirt-ubuntu-1804/main.yml @@ -21,8 +21,9 @@ os: name: 'Ubuntu' version: '1804' -package_format: 'deb' -package_manager: 'apt-get' +packaging: + format: 'deb' + command: 'apt-get' bash: /bin/bash cc: /usr/bin/gcc diff --git a/guests/lcitool b/guests/lcitool index 0a8ad49..89d5ef9 100755 --- a/guests/lcitool +++ b/guests/lcitool @@ -687,12 +687,12 @@ class Application: return r.read().rstrip() def _dockerfile_build_varmap(self, facts, mappings, pip_mappings, projects, cross_arch): - if facts["package_format"] == "deb": + if facts["packaging"]["format"] == "deb": varmap = self._dockerfile_build_varmap_deb(facts, mappings, pip_mappings, projects, cross_arch) - if facts["package_format"] == "rpm": + if facts["packaging"]["format"] == "rpm": varmap = self._dockerfile_build_varmap_rpm(facts, mappings, pip_mappings, projects, cross_arch) - varmap["package_manager"] = facts["package_manager"] + varmap["packaging_command"] = facts["packaging"]["command"] varmap["cc"] = facts["cc"] varmap["ccache"] = facts["ccache"] varmap["make"] = facts["make"] @@ -705,15 +705,12 @@ class Application: return varmap def _dockerfile_build_varmap_deb(self, facts, mappings, pip_mappings, projects, cross_arch): - package_format = facts["package_format"] - package_manager = facts["package_manager"] - pkgs = {} cross_pkgs = {} pip_pkgs = {} base_keys = [ "default", - package_format, + facts["packaging"]["format"], facts["os"]["name"], facts["os"]["name"] + facts["os"]["version"], ] @@ -752,7 +749,7 @@ class Application: if pkgs[package] is None or cross_policy in ["skip", "foreign"]: del pkgs[package] - pkg_align = " \\\n" + (" " * len("RUN " + package_manager + " ")) + pkg_align = " \\\n" + (" " * len("RUN " + facts["packaging"]["command"] + " ")) pip_pkg_align = " \\\n" + (" " * len("RUN pip3 ")) varmap = {} @@ -775,15 +772,12 @@ class Application: return varmap def _dockerfile_build_varmap_rpm(self, facts, mappings, pip_mappings, projects, cross_arch): - package_format = facts["package_format"] - package_manager = facts["package_manager"] - pkgs = {} cross_pkgs = {} pip_pkgs = {} keys = [ "default", - package_format, + facts["packaging"]["format"], facts["os"]["name"], facts["os"]["name"] + facts["os"]["version"], ] @@ -823,7 +817,7 @@ class Application: if cross_pkgs[package] is None: del cross_pkgs[package] - pkg_align = " \\\n" + (" " * len("RUN " + package_manager + " ")) + pkg_align = " \\\n" + (" " * len("RUN " + facts["packaging"]["format"] + " ")) pip_pkg_align = " \\\n" + (" " * len("RUN pip3 ")) varmap = {} @@ -838,30 +832,27 @@ class Application: return varmap def _dockerfile_format(self, facts, cross_arch, varmap): - package_format = facts["package_format"] - package_manager = facts["package_manager"] - print("FROM {}".format(facts["docker_base"])) commands = [] - if package_format == "deb": + if facts["packaging"]["format"] == "deb": commands.extend([ "export DEBIAN_FRONTEND=noninteractive", - "{package_manager} update", - "{package_manager} dist-upgrade -y", - "{package_manager} install --no-install-recommends -y {pkgs}", - "{package_manager} autoremove -y", - "{package_manager} autoclean -y", + "{packaging_command} update", + "{packaging_command} dist-upgrade -y", + "{packaging_command} install --no-install-recommends -y {pkgs}", + "{packaging_command} autoremove -y", + "{packaging_command} autoclean -y", "sed -Ei 's,^# (en_US\\.UTF-8 .*)$,\\1,' /etc/locale.gen", "dpkg-reconfigure locales", ]) - elif package_format == "rpm": + elif facts["packaging"]["format"] == "rpm": # Rawhide needs this because the keys used to sign packages are # cycled from time to time if facts["os"]["name"] == "Fedora" and facts["os"]["version"] == "Rawhide": commands.extend([ - "{package_manager} update -y --nogpgcheck fedora-gpg-keys" + "{packaging_command} update -y --nogpgcheck fedora-gpg-keys" ]) if facts["os"]["name"] == "CentOS": @@ -869,8 +860,8 @@ class Application: # the PowerTools repository, which is not enabled by default if facts["os"]["version"] != "7": commands.extend([ - "{package_manager} install 'dnf-command(config-manager)' -y", - "{package_manager} config-manager --set-enabled PowerTools -y", + "{packaging_command} install 'dnf-command(config-manager)' -y", + "{packaging_command} config-manager --set-enabled PowerTools -y", ]) # VZ development packages are only available for CentOS/RHEL-7 @@ -890,24 +881,24 @@ class Application: # Some of the packages we need are not part of CentOS proper # and are only available through EPEL commands.extend([ - "{package_manager} install -y epel-release", + "{packaging_command} install -y epel-release", ]) commands.extend([ - "{package_manager} update -y", - "{package_manager} install -y {pkgs}", + "{packaging_command} update -y", + "{packaging_command} install -y {pkgs}", ]) # openSUSE doesn't seem to have a convenient way to remove all # unnecessary packages, but CentOS and Fedora do if facts["os"]["name"] == "OpenSUSE": commands.extend([ - "{package_manager} clean --all", + "{packaging_command} clean --all", ]) else: commands.extend([ - "{package_manager} autoremove -y", - "{package_manager} clean all -y", + "{packaging_command} autoremove -y", + "{packaging_command} clean all -y", ]) commands.extend([ @@ -934,21 +925,21 @@ class Application: # Intentionally a separate RUN command from the above # so that the common packages of all cross-built images # share a Docker image layer. - if package_format == "deb": + if facts["packaging"]["format"] == "deb": cross_commands.extend([ "export DEBIAN_FRONTEND=noninteractive", "dpkg --add-architecture {cross_arch}", - "{package_manager} update", - "{package_manager} dist-upgrade -y", - "{package_manager} install --no-install-recommends -y dpkg-dev", - "{package_manager} install --no-install-recommends -y {cross_pkgs}", - "{package_manager} autoremove -y", - "{package_manager} autoclean -y", + "{packaging_command} update", + "{packaging_command} dist-upgrade -y", + "{packaging_command} install --no-install-recommends -y dpkg-dev", + "{packaging_command} install --no-install-recommends -y {cross_pkgs}", + "{packaging_command} autoremove -y", + "{packaging_command} autoclean -y", ]) - elif package_format == "rpm": + elif facts["packaging"]["format"] == "rpm": cross_commands.extend([ - "{package_manager} install -y {cross_pkgs}", - "{package_manager} clean all -y", + "{packaging_command} install -y {cross_pkgs}", + "{packaging_command} clean all -y", ]) cross_script = "\nRUN " + (" && \\\n ".join(cross_commands)) + "\n" @@ -985,11 +976,9 @@ class Application: host = hosts[0] facts = self._inventory.get_facts(host) - package_format = facts["package_format"] - package_manager = facts["package_manager"] cross_arch = args.cross_arch - if package_format not in ["deb", "rpm"]: + if facts["packaging"]["format"] not in ["deb", "rpm"]: raise Exception("Host {} doesn't support Dockerfiles".format(host)) if cross_arch: if facts["os"]["name"] not in ["Debian", "Fedora"]: diff --git a/guests/playbooks/update/tasks/base.yml b/guests/playbooks/update/tasks/base.yml index e962c56..d299988 100644 --- a/guests/playbooks/update/tasks/base.yml +++ b/guests/playbooks/update/tasks/base.yml @@ -10,7 +10,7 @@ - os.version == 'Rawhide' - name: Enable PowerTools repository - command: '{{ package_manager }} config-manager --set-enabled PowerTools -y' + command: '{{ packaging.command }} config-manager --set-enabled PowerTools -y' args: warn: no when: @@ -57,7 +57,7 @@ name: '*' state: latest when: - - package_format == 'rpm' + - packaging.format == 'rpm' - not ( os.name == 'Fedora' and os.version == 'Rawhide' ) @@ -71,7 +71,7 @@ - os.version == 'Rawhide' - name: Update installed packages - command: '{{ package_manager }} update --refresh --exclude "kernel*" -y' + command: '{{ packaging.command }} update --refresh --exclude "kernel*" -y' args: warn: no when: @@ -79,7 +79,7 @@ - os.version == 'Rawhide' - name: Update installed packages - command: '{{ package_manager }} update --disablerepo="*" --enablerepo=fedora-rawhide-kernel-nodebug "kernel*" -y' + command: '{{ packaging.command }} update --disablerepo="*" --enablerepo=fedora-rawhide-kernel-nodebug "kernel*" -y' args: warn: no when: @@ -91,32 +91,32 @@ upgrade: dist update_cache: yes when: - - package_format == 'deb' + - packaging.format == 'deb' - name: Update installed packages - shell: '{{ package_manager }} update && {{ package_manager }} upgrade -y' + shell: '{{ packaging.command }} update && {{ packaging.command }} upgrade -y' args: warn: no when: - - package_format == 'pkg' + - packaging.format == 'pkg' - name: Clean up packages after update - command: '{{ package_manager }} mark install "kernel*"' + command: '{{ packaging.command }} mark install "kernel*"' args: warn: no when: - os.name == 'Fedora' - name: Clean up packages after update - shell: '{{ package_manager }} clean packages -y && {{ package_manager }} autoremove -y' + shell: '{{ packaging.command }} clean packages -y && {{ packaging.command }} autoremove -y' args: warn: no when: - - package_format == 'rpm' + - packaging.format == 'rpm' - os.name != 'OpenSUSE' - name: Clean up packages after update - shell: '{{ package_manager }} clean' + shell: '{{ packaging.command }} clean' args: warn: no when: @@ -127,14 +127,14 @@ autoclean: yes autoremove: yes when: - - package_format == 'deb' + - packaging.format == 'deb' - name: Clean up packages after update - shell: '{{ package_manager }} clean -y && {{ package_manager }} autoremove -y' + shell: '{{ packaging.command }} clean -y && {{ packaging.command }} autoremove -y' args: warn: no when: - - package_format == 'pkg' + - packaging.format == 'pkg' - name: Configure hostname hostname: diff --git a/guests/playbooks/update/tasks/bootstrap.yml b/guests/playbooks/update/tasks/bootstrap.yml index 410fe66..ed36cb5 100644 --- a/guests/playbooks/update/tasks/bootstrap.yml +++ b/guests/playbooks/update/tasks/bootstrap.yml @@ -1,8 +1,8 @@ --- - name: Bootstrap the pkgng package manager - raw: 'env ASSUME_ALWAYS_YES=YES {{ package_manager }} bootstrap' + raw: 'env ASSUME_ALWAYS_YES=YES {{ packaging.command }} bootstrap' when: - - package_format == 'pkg' + - packaging.format == 'pkg' - name: Bootstrap Ansible - raw: '{{ package_manager }} install -y {{ ansible_python_package }}' + raw: '{{ packaging.command }} install -y {{ ansible_python_package }}' diff --git a/guests/playbooks/update/tasks/packages.yml b/guests/playbooks/update/tasks/packages.yml index 4517a86..f656cf5 100644 --- a/guests/playbooks/update/tasks/packages.yml +++ b/guests/playbooks/update/tasks/packages.yml @@ -30,11 +30,11 @@ - name: '{{ project }}: Look up mappings (package format)' set_fact: - resolved: '{{ resolved|combine({ item: mappings[item][package_format] }) }}' + resolved: '{{ resolved|combine({ item: mappings[item][packaging.format] }) }}' with_items: '{{ packages }}' when: - - mappings[item][package_format] is defined + - mappings[item][packaging.format] is defined - name: '{{ project }}: Look up mappings (OS name)' set_fact: @@ -62,11 +62,11 @@ - name: '{{ project }}: Look up mappings (arch with package format)' set_fact: - resolved: '{{ resolved|combine({ item: mappings[item]["x86_64" + "-" + package_format] }) }}' + resolved: '{{ resolved|combine({ item: mappings[item]["x86_64" + "-" + packaging.format] }) }}' with_items: '{{ packages }}' when: - - mappings[item]["x86_64" + "-" + package_format] is defined + - mappings[item]["x86_64" + "-" + packaging.format] is defined - name: '{{ project }}: Look up mappings (arch with OS name)' set_fact: diff --git a/guests/playbooks/update/tasks/services.yml b/guests/playbooks/update/tasks/services.yml index 81e282a..d4cf395 100644 --- a/guests/playbooks/update/tasks/services.yml +++ b/guests/playbooks/update/tasks/services.yml @@ -5,7 +5,7 @@ - set_fact: chrony: chronyd when: - - package_format != 'deb' + - packaging.format != 'deb' - name: 'Enable services' service: diff --git a/guests/playbooks/update/templates/bashrc.j2 b/guests/playbooks/update/templates/bashrc.j2 index 0f9c6c1..1c90a42 100644 --- a/guests/playbooks/update/templates/bashrc.j2 +++ b/guests/playbooks/update/templates/bashrc.j2 @@ -19,13 +19,13 @@ export OSINFO_SYSTEM_DIR="$VIRT_PREFIX/share/osinfo" # These search paths need to encode the OS architecture in some way # in order to work, so use the appropriate tool to obtain this # information and adjust them accordingly -package_format="{{ package_format }}" -if test "$package_format" = "deb"; then +packaging_format="{{ packaging.format }}" +if test "$packaging_format" = "deb"; then multilib=$(dpkg-architecture -q DEB_TARGET_MULTIARCH) export LD_LIBRARY_PATH="$VIRT_PREFIX/lib/$multilib:$LD_LIBRARY_PATH" export PKG_CONFIG_PATH="$VIRT_PREFIX/lib/$multilib/pkgconfig:$PKG_CONFIG_PATH" export GI_TYPELIB_PATH="$VIRT_PREFIX/lib/$multilib/girepository-1.0:$GI_TYPELIB_PATH" -elif test "$package_format" = "rpm"; then +elif test "$packaging_format" = "rpm"; then multilib=$(rpm --eval '%{_lib}') export LD_LIBRARY_PATH="$VIRT_PREFIX/$multilib:$LD_LIBRARY_PATH" export PKG_CONFIG_PATH="$VIRT_PREFIX/$multilib/pkgconfig:$PKG_CONFIG_PATH" -- 2.25.4