Ansible Playbook to Migrate RHEL Servers from Satellite5 to Satellite6
Below Playbook can be used to migrate any RHEL6 or RHEL7 server from Satellite version 5 to Satellite version 6.
I have considered the below Satellite organization setup.
1 Satellite Server and 2 capsule servers location at 2 different location/data-centers e.g east and west.
Satellite Server’s Hostname: rhnsat.example.com Capsule Server 1: rhnsatcap1.example.com Capsule Server 2: rhnsatcap2.example.com
---
- name: Playbook to Migrate servers from satellite5 to satellite6
hosts: sat6
become: true
become_method: sudo
serial: 1
vars:
satserver: rhnsat.example.com
cap1: rhnsatcap1.example.com
cap2: rhnsatcap2.example.com
tasks:
- name: Download and install a copy of the CA Certificate for Capsule 1
yum:
disable_gpg_check: yes
name: http://{{cap1}}/pub/katello-ca-consumer-latest.noarch.rpm
state: present
when: datacenter == "east"
- name: Download and install a copy of the CA Certificate for Capsule 2
yum:
disable_gpg_check: yes
name: http://{{cap2}}/pub/katello-ca-consumer-latest.noarch.rpm
state: present
when: datacenter == "west"
- name: Disable RHN Plugin
lineinfile:
path: /etc/yum/pluginconf.d/rhnplugin.conf
regexp: '^enabled'
line: 'enabled=0'
- name: Enable Subscription Manager Plugin
lineinfile:
path: /etc/yum/pluginconf.d/subscription-manager.conf
regexp: '^enabled'
line: 'enabled=1'
- name: Delete/Rename systemid file
command: mv /etc/sysconfig/rhn/systemid /etc/sysconfig/rhn/systemid.bak
ignore_errors: True
- name: Clean YUM Cache
command: yum clean all
ignore_errors: True
- name: Empty YUM Cache Directory
file:
state: "{{ item }}"
path: "/var/cache/yum/"
owner: root
group: root
mode: '0755'
with_items:
- absent
- directory
- name: Register RHEL7 Server to Satellite6
redhat_subscription:
state: present
activationkey: rhel7-key
org_id: org_label
when: ansible_distribution_major_version == "7"
- name: Register RHEL6 Virtual server to Satellite6
redhat_subscription:
state: present
activationkey: rhel6-key
org_id: org_label
when: ansible_distribution_major_version == "6"
- name: Install katello-agent
yum:
name: katello-agent
state: present
...
This playbook can be run using below command.
[root@ansible-host ~]# ansible-playbook sat5-sat6-migration.yml -e "datacenter=east"
Here, the datacenter variable can be replaced based on the server’s location i.e ease/west.