Register Spacewalk

- name: check if registered in spacewalk
  stat:
    path: /etc/sysconfig/rhn/systemid
  register: is_registered
 
- block:
    - name: add epel repository
      yum_repository:
        name: epel
        description: EPEL YUM repository
        baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
        state: present
 
    - name: install spacewalk-client
      yum:
        name: "{{ spacewalk_rpm }}"
        state: present
 
    - name: install required packages
      yum:
        name: "{{ item }}"
        state: present
      with_items:
          - python-hwdata
          - rhn-client-tools
          - rhn-check
          - rhn-setup
          - rhnsd
          - m2crypto
          - yum-rhn-plugin
          - gcc
          - gcc-c++
 
    - name: disable epel repository
      yum_repository:
        name: epel
        description: EPEL YUM repository
        baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
        enabled: no
 
    - name: install spacewalk CA
      yum:
        name: "{{ spacewalk_ssl }}"
        state: present
   
  when: is_registered.stat.exists == False