From bbbd367db74a3b772596af5d9a2f2cadb0a15855 Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Thu, 3 Aug 2017 07:33:50 -0500 Subject: [PATCH] Add dnf support This patch adds dnf support for CentOS. Implements: blueprint centos-ans-dnf Change-Id: I126b6fda107560e6ccc630dd7f4f930e954b4aaa --- .../common-tasks/package-cache-proxy.yml | 18 ++++++++++- playbooks/openstack-hosts-setup.yml | 32 +++---------------- scripts/bootstrap-ansible.sh | 5 ++- .../bootstrap-host/tasks/install_packages.yml | 2 +- .../tasks/prepare_networking.yml | 8 ++--- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/playbooks/common-tasks/package-cache-proxy.yml b/playbooks/common-tasks/package-cache-proxy.yml index 8cbb06bed5..9a96b1a39e 100644 --- a/playbooks/common-tasks/package-cache-proxy.yml +++ b/playbooks/common-tasks/package-cache-proxy.yml @@ -55,7 +55,9 @@ tags: - common-proxy -- name: Drop yum package manager proxy +# NOTE(mhayden): We always deploy the proxy configuration for yum on CentOS +# even if dnf is present. +- name: Deploy yum package manager proxy lineinfile: line: 'proxy={{ repo_pkg_cache_url }}' dest: "/etc/yum.conf" @@ -65,3 +67,17 @@ - repo_pkg_cache_enabled | bool tags: - common-proxy + +# NOTE(mhayden): If dnf and yum are installed on CentOS, we need to configure +# a proxy for dnf as well. +- name: Deploy dnf package manager proxy + lineinfile: + line: 'proxy={{ repo_pkg_cache_url }}' + dest: "/etc/dnf.conf" + state: "{{ (proxy_check.status == 200) | ternary('present', 'absent') }}" + when: + - ansible_os_family == 'RedHat' + - ansible_pkg_mgr == 'dnf' + - repo_pkg_cache_enabled | bool + tags: + - common-proxy diff --git a/playbooks/openstack-hosts-setup.yml b/playbooks/openstack-hosts-setup.yml index 46973a4682..0559529387 100644 --- a/playbooks/openstack-hosts-setup.yml +++ b/playbooks/openstack-hosts-setup.yml @@ -18,35 +18,11 @@ gather_facts: false user: root pre_tasks: - - name: Install Python2 + - name: Ensure python is installed register: result - raw: > - source /etc/os-release - - case ${ID} in - centos|rhel) - yum list installed python - result=$? - - if [ $result -eq 1 ]; then - yum -y install python2 - result=2 - fi - - exit $result; - ;; - ubuntu) - dpkg-query -s python &> /dev/null - result=$? - - if [ $result -eq 1 ]; then - apt-get -y install python - result=2 - fi - - exit $result; - ;; - esac + raw: apt-get -y install python + when: + - ansible_pkg_mgr == 'apt' changed_when: "result.rc == 2" failed_when: "{{ result.rc not in [0, 2] }}" diff --git a/scripts/bootstrap-ansible.sh b/scripts/bootstrap-ansible.sh index 556e0830c2..9450c1a2db 100755 --- a/scripts/bootstrap-ansible.sh +++ b/scripts/bootstrap-ansible.sh @@ -56,10 +56,13 @@ ssh_key_create # Determine the distribution which the host is running on determine_distro +# Prefer dnf over yum for CentOS. +which dnf &>/dev/null && RHT_PKG_MGR='dnf' || RHT_PKG_MGR='yum' + # Install the base packages case ${DISTRO_ID} in centos|rhel) - yum -y install \ + $RHT_PKG_MGR -y install \ git curl autoconf gcc gcc-c++ nc \ python2 python2-devel \ openssl-devel libffi-devel \ diff --git a/tests/roles/bootstrap-host/tasks/install_packages.yml b/tests/roles/bootstrap-host/tasks/install_packages.yml index 3d7e95f17b..943e7dfa97 100644 --- a/tests/roles/bootstrap-host/tasks/install_packages.yml +++ b/tests/roles/bootstrap-host/tasks/install_packages.yml @@ -88,7 +88,7 @@ retries: 5 delay: 2 when: - - ansible_pkg_mgr == 'yum' + - ansible_pkg_mgr in ['yum', 'dnf'] - name: Remove known problem packages package: diff --git a/tests/roles/bootstrap-host/tasks/prepare_networking.yml b/tests/roles/bootstrap-host/tasks/prepare_networking.yml index f21e3c6141..1e6e842c83 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_networking.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_networking.yml @@ -40,7 +40,7 @@ with_items: "{{ bridges }}" register: network_interfaces_rhel when: - - ansible_pkg_mgr == 'yum' + - ansible_pkg_mgr in ['yum', 'dnf'] - name: Create alias file when required (RedHat) template: @@ -48,7 +48,7 @@ dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0" with_items: "{{ bridges }}" when: - - ansible_pkg_mgr == 'yum' + - ansible_pkg_mgr in ['yum', 'dnf'] - item.alias is defined - name: Put down post-up script for veth-peer interfaces (RedHat) @@ -61,7 +61,7 @@ - "{{ bridges }}" when: - item[1].veth_peer is defined - - ansible_pkg_mgr == 'yum' + - ansible_pkg_mgr in ['yum', 'dnf'] - name: Ensure the postup/postdown scripts are loaded (RedHat) lineinfile: @@ -73,7 +73,7 @@ - "{{ bridges }}" when: - item[1].veth_peer is defined - - ansible_pkg_mgr == 'yum' + - ansible_pkg_mgr in ['yum', 'dnf'] - name: Copy multinode network configuration (Debian) template: