diff --git a/adhoc-convert-rhel.yml b/adhoc-convert-rhel.yml new file mode 100644 index 0000000..ad0f1af --- /dev/null +++ b/adhoc-convert-rhel.yml @@ -0,0 +1,53 @@ +# Convert CentOS Stream 8 nodes to RHEL 8 +--- +- hosts: "{{ target }}" + vars_prompt: + - name: "target" + prompt: "Host[s]/Group[s] to convert from Stream to RHEL ? => " + private: no + become: True + gather_facts: True + + + tasks: + + - import_role: + name: baseline + tasks_from: rhel + when: + - ansible_distribution_major_version == '8' + - ansible_distribution == 'CentOS' + + - block: + - name: Ensuring we can drop some TLS cdn files + file: + path: "{{ item }}" + state: directory + with_items: + - /etc/rhsm/ca + - /etc/pki/entitlement + + - name: Ensuring we have correct RHEL gpg pub key + copy: + src: "{{ item.file }}" + dest: "{{ item.dest }}" + loop: + - { file: '{{ pkistore }}/rpm/redhat-uep.pem', dest: '/etc/rhsm/ca/redhat-uep.pem' } + - { file: '{{ pkistore }}/rpm/RPM-GPG-KEY-redhat-release', dest: '/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release' } + + - name: Importing convert shell script + template: + src: convert-to-rhel + dest: /var/tmp/convert-to-rhel + mode: 0750 + owner: root + + - name: Converting to RHEL 8 + command: + cmd: /var/tmp/convert-to-rhel + register: result + changed_when: result.rc == 2 + failed_when: result.rc == 1 + when: + - ansible_distribution == 'CentOS' + - ansible_distribution_major_version == '8' diff --git a/templates/convert-to-rhel b/templates/convert-to-rhel new file mode 100755 index 0000000..9f6bf0d --- /dev/null +++ b/templates/convert-to-rhel @@ -0,0 +1,27 @@ +#!/bin/bash +logfile="/var/log/centos-convert-rhel.log" + +function f_log () { + echo "[+] $(date +%Y%m%d-%H:%M) stylo -> $*" >>$logfile +} + +f_log "Detecting if we have redhat-release package installed" +rpm -q redhat-release 2>&1 >/dev/null +if [ "$?" -eq "0" ] ; then + f_log "Detected $(rpm -q redhat-release) so exiting" + exit 0 +else + f_log "Forcing removal of centos-stream-repos and centos-stream-release pkgs ..." + rpm -e --nodeps centos-stream-repos centos-stream-release 2>&1 >>$logfile + f_log "Forcing dnf makecache from RHEL repositories ..." + dnf clean all --releasever {{ ansible_distribution_major_version }} >> $logfile + dnf makecache --releasever {{ ansible_distribution_major_version }} >> $logfile + dnf distro-sync -y -q --releasever {{ ansible_distribution_major_version }} >> $logfile 2>&1 + if [ "$?" -ne "0" ] ;then + echo "Error converting to RHEL 8" >> $logfile + exit 1 + else + exit 2 + fi +fi +