0% found this document useful (0 votes)
64 views12 pages

Migration of Centos To Rhel by Automation

Uploaded by

shubhamage1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views12 pages

Migration of Centos To Rhel by Automation

Uploaded by

shubhamage1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Migration of CentOS 7 to RHEL 7

Step1:- Check the OS version and kernel version.


# cat /etc/os-release

# uname -r

Step2 :- Update the yum packages

# yum update -y

Step3 :- Reboot the system after yum update

# reboot

Step4 :- configure the ansible host file

# vi /etc/ansible/hosts

Put the entry of host in the file.

Step5 :- Install conver2rhel utility

# vi setup-convert2rhel.yml

----Note :- copy the playbook---

- Check the syntax of playbook

# ansible-playbook setup-convert2rhel.yml --syntax-check

- Run the playbook setup-convert2rhel.yml

# ansible-playbook setup-convert2rhel.yml

Step6 :- run convert2rhel utility


- Check the syntax of playbook

# ansible-playbook run-convert2rhel.yml --syntax-check


- Run the playbook run-convert2rhel.yml

# ansible-playbook run-convert2rhel.yml
Step7 :- Check the OS version of client server
# cat /etc/os-release

===========================================================================

Playbook1 :- setup-convert2rhel.yml

- hosts: all

become: yes
strategy: free

# You may modify these to fit your environment or use ansible-playbook --extra-vars
# to override them if needed.

vars:
skip_os_version_check: false
centos8_repos:
- CentOS-Linux-AppStream.repo
- CentOS-Linux-BaseOS.repo

- CentOS-Linux-ContinuousRelease.repo
- CentOS-Linux-Devel.repo
- CentOS-Linux-Extras.repo
- CentOS-Linux-FastTrack.repo
- CentOS-Linux-HighAvailability.repo

- CentOS-Linux-Plus.repo
- CentOS-Linux-PowerTools.repo

tasks:

- name: Validate source distribution and major version


fail:
msg: "The system must be CentOS/Oracle/Alma/Rocky Linux 7 or 8"
when:

- ansible_distribution not in ['CentOS', 'OracleLinux', 'AlmaLinux', 'Rocky']


- ansible_distribution_major_version in ['7', '8']

- name: Patch repositories if dealing with CentOS8.


block:

- name: Comment mirrorlist in all repos.


replace:
path: /etc/yum.repos.d/{{ item }}
regexp: ^mirrorlist
replace: "#mirrorlist"

loop: "{{ centos8_repos }}"

- name: Switch repo to vault.centos.org.


replace:
path: /etc/yum.repos.d/{{ item }}

regexp: "#baseurl=http://mirror.centos.org"
replace: baseurl=https://vault.centos.org
loop: "{{ centos8_repos }}"
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version | int == 8

- name: Download Red Hat GPG key


get_url:
url: https://www.redhat.com/security/data/fd431d51.txt
dest: "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"

- name: Add Convert2RHEL yum repository from Red Hat


get_url:
url: https://ftp.redhat.com/redhat/convert2rhel/{{ ansible_distribution_major_version
}}/convert2rhel.repo
dest: "/etc/yum.repos.d/convert2rhel.repo"

- name: Install Convert2RHEL


yum:

name: convert2rhel

Playbook2:- run-convert2rhel.yml

- name: Run setup tasks

import_playbook: setup-convert2rhel.yml

- hosts: all
become: yes
strategy: free

# Modify these to be your red hat subscription manager username and password
# or override them via ansible-playbook --extra-vars
vars:
rhsm_username: redhat-user-name

rhsm_password: redhat-users-password

tasks:

- name: Running convert2rhel with password file

block:
# Put the password into a file as arguments on the commandline can be
# seen in the process list.
- name: Create a temporary file to hold the password
# Note: Temporary files are always created with a secure mode, 0600

tempfile:
state: file
suffix: .temp
path: ~/
register: password_file

- name: Save password in the temporary file


lineinfile:
path: "{{ password_file.path }}"
line: "{{ rhsm_password }}"

insertafter: EOF
no_log: True # Contains a secret

# NOTE 1: use the -y option to answer yes to all yes/no questions the
# tool asks carefully and only after you have tested interactively to

# ensure that there are not surprises within your environment. Also
# take care to read and follow all prerequisites and backup guidance documented at
# https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-
single/converting_from_an_rpm-based_linux_distribution_to_rhel/index

# NOTE 2: the following command may take 20-40 minutes on average to


# complete, depending on quantity of packages installed and speed of

# network and storage. This will need to be run in parallel from the
# control node or Tower to effectively run against many systems.

- name: Run Convert2RHEL


command: >
convert2rhel
-u "{{ rhsm_username }}"
--password-from-file "{{ password_file.path }}"

--auto-attach
--debug
# -y

always:

- name: Remove the temporary file


file:
path: "{{ password_file.path }}"
state: absent
when: password_file.path is defined

- name: reboot
reboot:

- name: recollect ansible facts on running distribution on system

setup:
gather_subset: 'distribution'

- name: Verify system is converted to Red Hat Enterprise Linux (RHEL)


assert:

that: ansible_distribution == 'RedHat'


msg: "OS conversion failed. OS is NOT Red Hat"
Screenshots for Reference:-
Client machine:-

After Migration

You might also like