blob: 74ee8bbfe03e7e6ca1b0ddf28a856cae878d556e (
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
69
70
71
72
73
74
75
76
77
78
79
80
81
|
---
- set_fact:
rhel_subscription_pass: "{{ lookup('env', 'rhel_subscription_pass') | default(rhsub_pass | default(omit, True)) }}"
rhel_subscription_pool: "{{ lookup('env', 'rhel_subscription_pool') | default(rhsub_pool | default('Red Hat OpenShift Container Platform, Premium*')) }}"
rhel_subscription_user: "{{ lookup('env', 'rhel_subscription_user') | default(rhsub_user | default(omit, True)) }}"
rhel_subscription_server: "{{ lookup('env', 'rhel_subscription_server') | default(rhsub_server | default(omit, True)) }}"
- fail:
msg: "This role is only supported for Red Hat hosts"
when: ansible_distribution != 'RedHat'
- fail:
msg: The rhel_subscription_user variable is required for this role.
when: rhel_subscription_user is not defined or not rhsub_user is not defined
- fail:
msg: The rhel_subscription_pass variable is required for this role.
when: rhel_subscription_pass is not defined or not rhsub_pass is not defined
- name: Install Red Hat Subscription manager
yum:
name: subscription-manager
state: present
register: result
until: result | success
- name: Is host already registered?
command: bash -c "subscription-manager version"
register: rh_subscribed
changed_when: "'not registered' in rh_subscribed.stdout"
ignore_errors: yes
- name: Register host
redhat_subscription:
username: "{{ rhel_subscription_user }}"
password: "{{ rhel_subscription_pass }}"
register: rh_subscription
until: rh_subscription | succeeded
when:
- "'not registered' in rh_subscribed.stdout"
- rhel_subscription_user is defined
- rhel_subscription_pass is defined
- fail:
msg: 'Unable to register host with Red Hat Subscription Manager'
when:
- "'not registered' in rh_subscribed.stdout"
- rh_subscription.failed
- name: Determine if OpenShift Pool Already Attached
command: bash -c "subscription-manager list --consumed --pool-only --matches '*OpenShift*' | grep {{ rhel_subscription_pool }}"
register: openshift_pool_attached
changed_when: rhel_subscription_pool not in openshift_pool_attached.stdout
failed_when: openshift_pool_attached.rc == 2
ignore_errors: yes
- name: Retrieve the OpenShift Pool ID
command: bash -c "subscription-manager list --available --pool-only --matches '*OpenShift*' | grep {{ rhel_subscription_pool }}"
register: openshift_pool_retrieve
changed_when: rhel_subscription_pool in openshift_pool_retrieve.stdout
when: rhel_subscription_pool not in openshift_pool_attached.stdout
ignore_errors: yes
- fail:
msg: "Unable to find pool matching {{ rhel_subscription_pool }} in available pools"
when:
- rhel_subscription_pool not in openshift_pool_attached.stdout
- rhel_subscription_pool not in openshift_pool_retrieve.stdout
- name: Attach to OpenShift Pool
command: bash -c "subscription-manager attach --pool {{ rhel_subscription_pool }}"
register: openshift_pool_attached
changed_when: "'Successfully attached a subscription' in openshift_pool_attached.stdout"
when: rhel_subscription_pool not in openshift_pool_attached.stdout
- include_role:
role: rhel_subscribe
tasks_from: satellite
when:
- (rhel_subscription_server or rhsub_server) is defined
- (rhel_subscription_server or rhsub_server)
|