Sunday 4 June 2017

Ansible playbook to register rhel 6 and rhel 7 clients to satellite 6

Below playbook can be used to register rhel 6/7 clients to get unregistered from existing satellite 5 and registers it to satellite 6.

The clients gets registered with respective activation key in my case the activation key names are RHEL6 and RHEL7.

# ansible-playbook register.yml --extra-vars "host=givehostip|groupname" --extra-vars "satelliteip=givesatelliteip" --user ranjith

---
- hosts: "{{ host }}"
  become: yes
  become_method: sudo
  tasks:
    - name: Download and install a copy of the CA Certificate for the Red Hat Satellite 6 server
      yum:
        disable_gpg_check: yes
        name: http://{{satelliteip}}/pub/katello-ca-consumer-latest.noarch.rpm
        state: present
      when:
        - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"
    - name: Setting enabled=1 in subscription-manager.conf
      lineinfile:
        path: /etc/yum/pluginconf.d/subscription-manager.conf
        regexp: '^enabled'
        line: 'enabled=1'
      when:
        - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"
    - name: Setting enabled=0 in rhnplugin.conf
      lineinfile:
        path: /etc/yum/pluginconf.d/rhnplugin.conf
        regexp: '^enabled'
        line: 'enabled=0'
      when:
        - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"
    - name: delete the rhn registration locally
      command: mv /etc/sysconfig/rhn/systemid /etc/sysconfig/rhn/systemid.bak
      when:
        - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"
      ignore_errors: True
    - name: Register with activationkey matching Red Hat Enterprise Server Version 6
      redhat_subscription:
        state: present
        activationkey: RHEL6
        org_id: Default_Organization
      when:
        - ansible_distribution_major_version == "6"
    - name: Register with activationkey matching Red Hat Enterprise Server Version 7
      redhat_subscription:
        state: present
        activationkey: RHEL7
        org_id: Default_Organization
      when:
        - ansible_distribution_major_version == "7"
    - name: Skipping server matching Red Hat Enterprise Server Version 5
      shell: echo "This certainly is history!"
      when:
        - ansible_distribution_major_version == "5"
    - name: Install katello-agent
      yum:
        name: katello-agent
        state: present
      when:
        - ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7"

2 comments: