summaryrefslogtreecommitdiffstats
path: root/roles/rhel_subscribe
diff options
context:
space:
mode:
Diffstat (limited to 'roles/rhel_subscribe')
-rw-r--r--roles/rhel_subscribe/meta/main.yml2
-rw-r--r--roles/rhel_subscribe/tasks/enterprise.yml25
-rw-r--r--roles/rhel_subscribe/tasks/main.yml73
3 files changed, 100 insertions, 0 deletions
diff --git a/roles/rhel_subscribe/meta/main.yml b/roles/rhel_subscribe/meta/main.yml
new file mode 100644
index 000000000..23d65c7ef
--- /dev/null
+++ b/roles/rhel_subscribe/meta/main.yml
@@ -0,0 +1,2 @@
+---
+dependencies: []
diff --git a/roles/rhel_subscribe/tasks/enterprise.yml b/roles/rhel_subscribe/tasks/enterprise.yml
new file mode 100644
index 000000000..fa74c9953
--- /dev/null
+++ b/roles/rhel_subscribe/tasks/enterprise.yml
@@ -0,0 +1,25 @@
+---
+- name: Disable all repositories
+ command: subscription-manager repos --disable="*"
+
+- set_fact:
+ default_ose_version: '3.6'
+ when: deployment_type == 'openshift-enterprise'
+
+- set_fact:
+ ose_version: "{{ lookup('env', 'ose_version') | default(default_ose_version, True) }}"
+
+- fail:
+ msg: "{{ ose_version }} is not a valid version for {{ deployment_type }} deployment type"
+ when:
+ - deployment_type == 'openshift-enterprise'
+ - ose_version not in ['3.1', '3.2', '3.3', '3.4', '3.5', '3.6'] )
+
+- name: Enable RHEL repositories
+ command: subscription-manager repos \
+ --enable="rhel-7-server-rpms" \
+ --enable="rhel-7-server-extras-rpms" \
+ --enable="rhel-7-server-ose-{{ ose_version }}-rpms" \
+ --enable="rhel-7-fast-datapath-rpms"
+ register: subscribe_repos
+ until: subscribe_repos | succeeded
diff --git a/roles/rhel_subscribe/tasks/main.yml b/roles/rhel_subscribe/tasks/main.yml
new file mode 100644
index 000000000..b06f51908
--- /dev/null
+++ b/roles/rhel_subscribe/tasks/main.yml
@@ -0,0 +1,73 @@
+---
+# TODO: Enhance redhat_subscription module
+# to make it able to attach to a pool
+# to make it able to enable repositories
+
+- set_fact:
+ 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_pass: "{{ lookup('env', 'rhel_subscription_pass') | default(rhsub_pass | 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: Either rhsub_user or the rhel_subscription_user env variable are required for this role.
+ when: rhel_subscription_user is not defined
+
+- fail:
+ msg: Either rhsub_pass or the rhel_subscription_pass env variable are required for this role.
+ when: rhel_subscription_pass is not defined
+
+- name: Detecting Atomic Host Operating System
+ stat:
+ path: /run/ostree-booted
+ register: ostree_booted
+
+- name: Satellite preparation
+ command: "rpm -Uvh http://{{ rhel_subscription_server }}/pub/katello-ca-consumer-latest.noarch.rpm"
+ args:
+ creates: /etc/rhsm/ca/katello-server-ca.pem
+ when: rhel_subscription_server is defined and rhel_subscription_server
+
+- name: Install Red Hat Subscription manager
+ yum:
+ name: subscription-manager
+ state: present
+
+- name: RedHat subscriptions
+ redhat_subscription:
+ username: "{{ rhel_subscription_user }}"
+ password: "{{ rhel_subscription_pass }}"
+ register: rh_subscription
+ until: rh_subscription | succeeded
+
+- name: Retrieve the OpenShift Pool ID
+ command: subscription-manager list --available --matches="{{ rhel_subscription_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="{{ rhel_subscription_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 {{ rhel_subscription_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: enterprise.yml
+ when:
+ - deployment_type == 'openshift-enterprise'
+ - not ostree_booted.stat.exists | bool