summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorVinny Valdez <vvaldez@redhat.com>2016-03-30 15:46:31 -0500
committerVinny Valdez <vvaldez@redhat.com>2016-04-20 09:28:48 -0500
commit177950b76a185c20317aa0e89d356cdf8b97c4c3 (patch)
tree876ab46e2daaba35adf64e47bbcb727b6bf30f8a /roles
parent80c3d3332507fe620fcab99e65f2ffd81d48a69e (diff)
downloadopenshift-177950b76a185c20317aa0e89d356cdf8b97c4c3.tar.gz
openshift-177950b76a185c20317aa0e89d356cdf8b97c4c3.tar.bz2
openshift-177950b76a185c20317aa0e89d356cdf8b97c4c3.tar.xz
openshift-177950b76a185c20317aa0e89d356cdf8b97c4c3.zip
Refactor role to dynamically determine rhsm_method
* Removes rhsm_method * Renames rhsm_server to rhsm_satellite * Add additional pre_task checks (hosted + key) * Change conditionals from rhsm_method check to rhsm_satellite defined * Change repos disable/enable from key to if repos are defined * Update README and examples in inventory file
Diffstat (limited to 'roles')
-rw-r--r--roles/subscription-manager/README.md30
-rw-r--r--roles/subscription-manager/pre_tasks/pre_tasks.yml41
-rw-r--r--roles/subscription-manager/tasks/main.yml20
3 files changed, 46 insertions, 45 deletions
diff --git a/roles/subscription-manager/README.md b/roles/subscription-manager/README.md
index b140ad09a..e604c7475 100644
--- a/roles/subscription-manager/README.md
+++ b/roles/subscription-manager/README.md
@@ -2,21 +2,11 @@
## Parameters
-This role depends on user specified variables. These can be set in the inventory file, group_vars or passed to the playbook from the CLI. The variables are:
+This role depends on user specified variables. These can be set in the inventory file, group_vars or passed to the playbook from the CLI. No values are set by default which disables this role. The variables are:
-### rhsm_method
+### rhsm_satellite
-Subscription Manager method to use for registration. Valid values are:
-
-* **satellite** - Use a Satellite server. Additional variables required include **rhsm_server**, **rhsm_org** and either (**rhsm_username** and **rhsm_password**) or **rhsm_activationkey**
-* **hosted** - Use Red Hat's CDN. Additional variables required are **rhsm_server** (defaults to RHSM CDN) and **rhsm_username** and **rhsm_password**
-* none/false/blank will disable any subscription manager activities (this is the default if no parameters are set)
-
-Default: none
-
-### rhsm_server
-
-Subscription Manager server hostname. If using a Satellite server set the FQDN here. If using RHSM Hosted this value is ignored.
+Subscription Manager server hostname. If using a Satellite server set the FQDN here. If using RHSM Hosted this value must be left blank, none or false.
Default: none
@@ -34,13 +24,13 @@ Default: none
### rhsm_org
-Optional Satellite Subscription Manager Organization. Required for Satellite, ignored if using RHSM Hosted.
+Optional Subscription Manager Satellite Organization. Required for Satellite, ignored if using RHSM Hosted.
Default: none
### rhsm_activationkey
-Optional Satellite Subscription Manager Activation Key, use this instead of **rhsm_username** and **rhsm_password** if using Satellite to provide repositories and authentication in a key instead.
+Optional Subscription Manager Satellite Activation Key, use this instead of **rhsm_username** and **rhsm_password** if using Satellite to provide repositories and authentication in a key instead.
Default: none
@@ -52,7 +42,7 @@ Default: none
### rhsm_repos
-Optional Repositories to enable, this can also be specified in the **rhsm_activationkey**. Valid for RHSM Hosted or Satellite. Specifying **rhsm_activationkey** will ignore this option.
+Optional list of repositories to enable. If left blank it is expected that the **rhsm_activationkey** will specify repos instead. If populated, a **subscription-manager repos --disable=\*** will be run and each of the specified repos explicitly enabled. Valid for RHSM Hosted or Satellite
NOTE: If specifying this value in an inventory file as opposed to group_vars, be sure to define it as a proper list as such:
@@ -75,7 +65,7 @@ The bulk of the work is performed in the main.yml for this role. The pre-task pl
```
roles:
- - { role: subscription-manager, when: not hostvars.localhost.rhsm_skip, tags: 'subscription-manager' }
+ - { role: subscription-manager, when: hostvars.localhost.rhsm_register, tags: 'subscription-manager' }
```
## Running the Playbook
@@ -83,13 +73,13 @@ The bulk of the work is performed in the main.yml for this role. The pre-task pl
To register to RHSM Hosted with username and password:
```
-ansible-playbook -i inventory/ose-provision ose-provision.yml -e "rhsm_method='hosted' rhsm_username=vvaldez rhsm_password='hunter2' openstack_key_name='vvaldez'"
+ansible-playbook -i inventory/ose-provision ose-provision.yml -e "rhsm_username=vvaldez rhsm_password=hunter2"
```
To register to a Satellite server with an activation key:
```
-ansible-playbook -i inventory/ose-provision ose-provision.yml -e "rhsm_server='10.12.32.1' rhsm_org='cloud_practice' rhsm_activationkey='rhel-7-ose-3-1' openstack_key_name='vvaldez' rhsm_method='satellite'"
+ansible-playbook -i inventory/ose-provision ose-provision.yml -e "rhsm_satellite=satellite.example.com rhsm_org=example_org rhsm_activationkey=rhel-7-ose-3-1"
```
-To ignore any Subscription Manager activities, simple do not set any parameters or explicitly set **rhsm_method** to false.
+To ignore any Subscription Manager activities, simply do not set any parameters.
diff --git a/roles/subscription-manager/pre_tasks/pre_tasks.yml b/roles/subscription-manager/pre_tasks/pre_tasks.yml
index 497f39353..dcd56b2b9 100644
--- a/roles/subscription-manager/pre_tasks/pre_tasks.yml
+++ b/roles/subscription-manager/pre_tasks/pre_tasks.yml
@@ -1,37 +1,40 @@
---
- name: Initialize Subscription Manager fact
set_fact:
- rhsm_skip: false
+ rhsm_register: true
-- name: Determine if Subscription Manager should be skipped or not
+- name: Determine if Subscription Manager should be used
set_fact:
- rhsm_skip: true
- when: rhsm_method is undefined or rhsm_method is none or rhsm_method|trim == ''
-
-- name: Determine Subscription Manager method
- fail: msg="Value for 'rhsm_method' of '{{ rhsm_method }}' is not valid, it should be one of 'hosted', 'satellite', or false/none/blank"
- when:
- - rhsm_method != 'hosted' and rhsm_method != 'satellite'
- - not rhsm_skip
-
-- name: Validate Subscription Manager host is set
- fail: msg="Cannot determine Subscription Manager server hostname without a value for 'rhsm_server'"
+ rhsm_register: false
when:
- - rhsm_server is undefined or rhsm_server is none or rhsm_server|trim == ''
- - not rhsm_method == 'hosted'
- - not rhsm_skip
+ - rhsm_satellite is undefined or rhsm_satellite is none or rhsm_satellite|trim == ''
+ - rhsm_username is undefined or rhsm_username is none or rhsm_username|trim == ''
+ - rhsm_password is undefined or rhsm_password is none or rhsm_password|trim == ''
+ - rhsm_org is undefined or rhsm_org is none or rhsm_org|trim == ''
+ - rhsm_activationkey is undefined or rhsm_activationkey is none or rhsm_activationkey|trim == ''
+ - rhsm_pool is undefined or rhsm_pool is none or rhsm_pool|trim == ''
- name: Validate Subscription Manager organization is set
fail: msg="Cannot register to a Satellite server without a value for the Organization via 'rhsm_org'"
when:
- rhsm_org is undefined or rhsm_org is none or rhsm_org|trim == ''
- - rhsm_method == 'satellite'
- - not rhsm_skip
+ - rhsm_satellite is defined
+ - rhsm_satellite is not none
+ - rhsm_satellite|trim != ''
+ - rhsm_register
- name: Validate Subscription Manager authentication is defined
fail: msg="Cannot register without ('rhsm_username' and 'rhsm_password') or 'rhsm_activationkey' variables set"
when:
- (rhsm_username is undefined or rhsm_username is none or rhsm_username|trim == '') or (rhsm_password is undefined or rhsm_password is none or rhsm_password|trim == '')
- rhsm_activationkey is undefined or rhsm_activationkey is none or rhsm_activationkey|trim == ''
- - not rhsm_skip
+ - rhsm_register
+- name: Validate activation key and Hosted are not requested together
+ fail: msg="Cannot register to RHSM Hosted with 'rhsm_activationkey'"
+ when:
+ - rhsm_satellite is undefined or rhsm_satellite is none or rhsm_satellite|trim == ''
+ - rhsm_activationkey is defined
+ - rhsm_activationkey is not none
+ - rhsm_activationkey|trim != ''
+ - rhsm_register
diff --git a/roles/subscription-manager/tasks/main.yml b/roles/subscription-manager/tasks/main.yml
index 2e04a7a22..78ceaccd1 100644
--- a/roles/subscription-manager/tasks/main.yml
+++ b/roles/subscription-manager/tasks/main.yml
@@ -32,7 +32,7 @@
changed_when: no
register: check_if_registered
-- name: Set registration fact
+- name: Set registration fact if system is already registered
set_fact:
registered: true
when: check_if_registered.rc == 0
@@ -44,17 +44,21 @@
- rhsm_authentication is defined
- name: Install Satellite certificate
- command: "rpm -Uvh --force http://{{ rhsm_server }}/pub/katello-ca-consumer-latest.noarch.rpm"
+ command: "rpm -Uvh --force http://{{ rhsm_satellite }}/pub/katello-ca-consumer-latest.noarch.rpm"
when:
- not registered
- - rhsm_method == 'satellite'
+ - rhsm_satellite is defined
+ - rhsm_satellite is not none
+ - rhsm_satellite|trim != ''
- name: Register to Satellite using activation key
command: "/usr/bin/subscription-manager register --activationkey={{ rhsm_activationkey }} --org={{ rhsm_org }}"
when:
- not registered
- rhsm_authentication == 'key'
- - rhsm_method == 'satellite'
+ - rhsm_satellite is defined
+ - rhsm_satellite is not none
+ - rhsm_satellite|trim != ''
# This can apply to either Hosted or Satellite
- name: Register using username and password
@@ -80,14 +84,18 @@
command: "/usr/bin/subscription-manager repos --disable=*"
when:
- not registered
- - not rhsm_authentication == "key"
+ - rhsm_repos is defined
+ - rhsm_repos is not none
+ - rhsm_repos|trim != ''
- name: Enable specified repositories
command: "/usr/bin/subscription-manager repos --enable={{ item }}"
with_items: rhsm_repos
when:
- not registered
- - not rhsm_authentication == "key"
+ - rhsm_repos is defined
+ - rhsm_repos is not none
+ - rhsm_repos|trim != ''
- name: Cleaning yum repositories
command: "yum clean all"