Skip to content

Commit

Permalink
Adding playbook to 'only' update Satellite Server admin (#316)
Browse files Browse the repository at this point in the history
* Adding playbook to 'only' update Satellite Server admin

* Updated Satellite playbook

* Updated Satellite playbook

* Updated Activation key tasks

* Fixing left-over 'satellite_servers'
  • Loading branch information
oybed authored and tylerauerbeck committed Jan 21, 2019
1 parent 3bf9465 commit ee18953
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 53 deletions.
7 changes: 5 additions & 2 deletions inventory/satellite-server/group_vars/satellite-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@ satellite_sync_plan: "CASL"

# Add some activation keys that the users can utilize
satellite_activation_keys:
casl-rhel:
subscription: "MySubs"
- name: "casl-rhel1"
subscription: "MySubs"
type: "Physical"
- name: "casl-rhel2"
subscription: "MySubs"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- hosts: satellite-server
pre_tasks:
- import_tasks: generate-lvm-list.yml
- import_tasks: generate-lvm-list.yml
roles:
- role: config-lvm
- role: config-satellite
- role: config-lvm
- role: config-satellite
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- hosts: satellite-server
tasks:
- import_role:
name: config-satellite
tasks_from: manifest
tags:
- 'update_manifest'
- import_role:
name: config-satellite
tasks_from: repos
tags:
- 'update_repos'
- import_role:
name: config-satellite
tasks_from: activation_keys
tags:
- 'update_activation_keys'
2 changes: 1 addition & 1 deletion playbooks/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
- configure_idm

- name: 'Configure Satellite'
hosts: satellite_servers
hosts: satellite-server
roles:
- role: config-satellite
tags:
Expand Down
2 changes: 1 addition & 1 deletion roles/config-satellite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Example Playbook

```
- name: 'Configure Satellite'
hosts: satellite_servers
hosts: satellite-server
roles:
- role: config-satellite
```
Expand Down
48 changes: 5 additions & 43 deletions roles/config-satellite/tasks/activation_keys.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,11 @@
---

- name: "Get current subscriptions"
shell: hammer -u "{{ satellite_username }}" -p "{{ satellite_password }}" --csv subscription list --organization "{{ satellite_organization }}" | grep "{{ item.value.subscription }}" | awk -F, '{print $1}'
shell: hammer -u "{{ satellite_username }}" -p "{{ satellite_password }}" --output=yaml subscription list --organization "{{ satellite_organization }}"
register: subids
with_dict: "{{ satellite_activation_keys }}"

- name: "Create activation key(s)"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key create
--name {{ item.key }}
--lifecycle-environment Library
--organization "{{ satellite_organization }}"
with_dict: "{{ satellite_activation_keys }}"
register: chk_ak
failed_when:
- chk_ak.rc != 65
- chk_ak.rc != 0

- name: "Add subs to activation key"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key add-subscription
--name "{{ item.item.key }}"
--subscription-id "{{ item.stdout }}"
--organization "{{ satellite_organization }}"
with_items:
- "{{ subids.results }}"
register: ak_chk
failed_when:
- ak_chk.rc != 128
- ak_chk.rc != 0

- name: "Turn off autoattach on activation key(s)"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key update
--auto-attach false
--name "{{ item.key }}"
--organization "{{ satellite_organization }}"
with_dict: "{{ satellite_activation_keys }}"
- include_tasks: process-one-activation-key.yml
loop: "{{ satellite_activation_keys }}"
loop_control:
loop_var: activation_key

3 changes: 2 additions & 1 deletion roles/config-satellite/tasks/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
subscription upload
--file /root/manifest.zip
--organization "{{ satellite_organization }}"
when: copy_sub|changed
when:
- copy_sub.changed


47 changes: 47 additions & 0 deletions roles/config-satellite/tasks/process-one-activation-key.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---

- name: "Create activation key"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key create
--name "{{ activation_key.name }}"
--lifecycle-environment Library
--organization "{{ satellite_organization }}"
register: chk_ak
failed_when:
- chk_ak.rc != 65
- chk_ak.rc != 0

- name: "Add subs to activation key"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key add-subscription
--name "{{ activation_key.name }}"
--subscription-id "{{ item.ID }}"
--organization "{{ satellite_organization }}"
when:
- (activation_key.type is defined and
item.Type == activation_key.type and
item.Name == activation_key.subscription) or
(activation_key.type is undefined and
item.Name == activation_key.subscription)
with_items:
- "{{ subids.stdout | from_yaml }}"
register: ak_chk
failed_when:
- ak_chk.rc != 128
- ak_chk.rc != 0

- name: "Turn off autoattach on activation key(s)"
command: >
hammer
-u "{{ satellite_username }}"
-p "{{ satellite_password }}"
activation-key update
--auto-attach false
--name "{{ activation_key.name }}"
--organization "{{ satellite_organization }}"
2 changes: 1 addition & 1 deletion roles/config-satellite/tests/hosts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

[satellite_servers]
[satellite-server]
sat.example.com ansible_user=root ansible_host=192.168.1.10
2 changes: 1 addition & 1 deletion roles/config-satellite/tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: 'Configure Satellite'
hosts: satellite_servers
hosts: satellite-server
roles:
- role: config-satellite

0 comments on commit ee18953

Please sign in to comment.