summaryrefslogtreecommitdiffstats
path: root/roles/rhel_subscribe/tasks/main.yml
blob: 3466b7e44ed3bad7dc0daae5d3fa12871b1f69a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
---
# TODO: Enhance redhat_subscription module
#       to make it able to attach to a pool
#       to make it able to enable repositories

- fail:
    msg: "This role is only supported for Red Hat hosts"
  when: ansible_distribution != 'RedHat'

- fail:
    msg: The rhsub_user variable is required for this role.
  when: rhsub_user is not defined or not rhsub_user

- fail:
    msg: The rhsub_pass variable is required for this role.
  when: rhsub_pass is not defined or not rhsub_pass

- name: Detecting Atomic Host Operating System
  stat:
    path: /run/ostree-booted
  register: ostree_booted

- name: Satellite preparation
  command: "rpm -Uvh http://{{ rhsub_server }}/pub/katello-ca-consumer-latest.noarch.rpm"
  args:
    creates: /etc/rhsm/ca/katello-server-ca.pem
  when: rhsub_server is defined and rhsub_server

- name: Install Red Hat Subscription manager
  yum:
    name: subscription-manager
    state: present
  register: result
  until: result | success

- name: RedHat subscriptions
  redhat_subscription:
    username: "{{ rhsub_user }}"
    password: "{{ rhsub_pass }}"
  register: rh_subscription
  until: rh_subscription | succeeded

- name: Retrieve the OpenShift Pool ID
  command: subscription-manager list --available --matches="{{ rhsub_pool }}" --pool-only
  register: openshift_pool_id
  until: openshift_pool_id | succeeded
  changed_when: False

- name: Determine if OpenShift Pool Already Attached
  command: subscription-manager list --consumed --matches="{{ rhsub_pool }}" --pool-only
  register: openshift_pool_attached
  until: openshift_pool_attached | succeeded
  changed_when: False
  when: openshift_pool_id.stdout == ''

- fail:
    msg: "Unable to find pool matching {{ rhsub_pool }} in available or consumed pools"
  when: openshift_pool_id.stdout == '' and openshift_pool_attached is defined and openshift_pool_attached.stdout == ''

- name: Attach to OpenShift Pool
  command: subscription-manager attach --pool {{ openshift_pool_id.stdout_lines[0] }}
  register: subscribe_pool
  until: subscribe_pool | succeeded
  when: openshift_pool_id.stdout != ''

- include_tasks: enterprise.yml
  when:
  - not ostree_booted.stat.exists | bool