From b98e464f0789a72067d4ccb1442133cbfc9c9d10 Mon Sep 17 00:00:00 2001 From: Ethan Paul Date: Sun, 1 Dec 2019 14:46:49 -0500 Subject: [PATCH] Update packages role to better handle cent7 vs 8 --- .../{centos-dracut.yml => centos-8-dracut.yml} | 3 +++ roles/packages/tasks/centos-repos.yml | 17 +++++++++++++++-- roles/packages/tasks/clean.yml | 9 ++++++++- roles/packages/tasks/update.yml | 17 +++++++++++++---- 4 files changed, 39 insertions(+), 7 deletions(-) rename roles/packages/tasks/{centos-dracut.yml => centos-8-dracut.yml} (98%) diff --git a/roles/packages/tasks/centos-dracut.yml b/roles/packages/tasks/centos-8-dracut.yml similarity index 98% rename from roles/packages/tasks/centos-dracut.yml rename to roles/packages/tasks/centos-8-dracut.yml index d78ff53..3aeecae 100644 --- a/roles/packages/tasks/centos-dracut.yml +++ b/roles/packages/tasks/centos-8-dracut.yml @@ -8,6 +8,9 @@ # # TODO: Host the RPMs locally. The internet may never forget, but it's also never there # when you need it +# +# NOTE: These tasks only need to be run on Cent8 +# - name: Determine dracut version shell: diff --git a/roles/packages/tasks/centos-repos.yml b/roles/packages/tasks/centos-repos.yml index 5f95996..72bc706 100644 --- a/roles/packages/tasks/centos-repos.yml +++ b/roles/packages/tasks/centos-repos.yml @@ -1,13 +1,26 @@ --- -- name: Enable Extra Packages for Enterprise Linux +# NOTE: We assume- since this file literally has 'centos' in the name- that the +# ansible_distribution check has already been done at import time + +- name: Enable Extra Packages for Enterprise Linux on CentOS 8 become: true + when: ansible_distribution_major_version == "8" dnf: state: latest name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -- name: Enable the power tools repository +- name: Enable the power tools repository on CentOS 8 become: true + when: ansible_distribution_major_version == "8" lineinfile: path: /etc/yum.repos.d/CentOS-PowerTools.repo regexp: "enabled=(0|1)" line: "enabled=1" + + +- name: Enable Extra Packages for Enterprise Linux on CentOS 7 + become: true + when: ansible_distribution_major_version == "7" + dnf: + state: latest + name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpmz diff --git a/roles/packages/tasks/clean.yml b/roles/packages/tasks/clean.yml index 934f71a..c4524ed 100644 --- a/roles/packages/tasks/clean.yml +++ b/roles/packages/tasks/clean.yml @@ -1,7 +1,14 @@ --- - name: Clean DNF cache become: true - when: ansible_distribution == "Fedora" or ansible_distribution == "CentOS" + when: ansible_distribution == "Fedora" or (ansible_distribution == "CentOS" and ansible_distribution_major_version == "8") shell: cmd: dnf clean all warn: false + +- name: Clean YUM cache + become: true + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" + shell: + cmd: yum clean all + warn: false diff --git a/roles/packages/tasks/update.yml b/roles/packages/tasks/update.yml index 7315789..2d245d3 100644 --- a/roles/packages/tasks/update.yml +++ b/roles/packages/tasks/update.yml @@ -1,15 +1,24 @@ --- -- import_tasks: centos-dracut.yml - when: ansible_distribution == "CentOS" +- import_tasks: centos-8-dracut.yml + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "8" -- name: Upgrade Fedora and CentOS packages - when: ansible_distribution == "CentOS" or ansible_distribution == "Fedora" +- name: Upgrade Fedora and CentOS 8 packages + when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "8") or ansible_distribution == "Fedora" become: true dnf: state: latest name: "*" exclude: "{{ ','.join(exclude | default(['kernel*'])) }}" +- name: Upgrade CentOS 7 packages + when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7" + become: true + yum: + state: latest + name: "*" + exclude: "{{ ','.join(exclude | default(['kernel*'])) }}" + +# Yeah I'll get here eventually # - name: Upgrade APT packages # when: ansible_distribution == "Debian" or ansible_distribution == "Ubuntu" # become: true