Skip to content

Commit

Permalink
Added update for composite content view
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Gerbron committed Nov 3, 2017
1 parent a4958c0 commit 1f17686
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ This role expects a satellite user with sufficient privileges.
Sometimes it can be beneficial to automatically update specific content views, for example the base operating system content view.
Satellite can schedule syncs of the repositories, but the synced content will not be available to the clients until the administrator publishes a new version of a content view containing these repositories.

**WARNING**: Regarding composite content views, this will for the moment only publish a new version of the composite content view, without updating versions of inner content views.
**WARNING**: Regarding composite content views, this will update inner composite views to their latest version before publishing.

``` yml
---
Expand Down Expand Up @@ -116,7 +116,7 @@ The number of kept versions can be adjusted using variable `sat_keep_old_cv`.
sat_cv_name: content_view_name
sat_publish: no
sat_remove_old_cv: yes
sat_keep_old_cv: 5
sat_keep_old_cv: 5
roles:
- satellite6-content_views
```
Expand Down
11 changes: 11 additions & 0 deletions tasks/build_component_ids.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: Getting versions list of current content view
set_fact:
current_cv_version_list: "{{ content_view_list.json | to_json | from_json | json_query(query_ccv_cv_version_list) }}"

- name: Adding latest version id of each content views
set_fact:
sat_ccv_component_ids: "{{ sat_ccv_component_ids + [ inner_item.id ] }}"
when: 1 in inner_item.environment_ids
with_items: "{{ current_cv_version_list }}"
loop_control:
loop_var: inner_item
17 changes: 12 additions & 5 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#Check vars
#Cannot set sat_publish to yes is there is no name in sat_cv_name
- name: Checking content view publish variables
fail: msg="If variable sat_publish has been set to yes, you must specify a content view name with sat_cv_name"
when: sat_cv_name == '' and sat_publish
- name: Checking content view name
fail: msg="You must specify a content view name with sat_cv_name"
when: sat_cv_name == ''

#Cannot set sat_promote_to_env to yes is there is no name in sat_env_name
- name: Checking env promote variables
Expand Down Expand Up @@ -41,19 +41,26 @@
sat_cv_id: "{{ content_view_list.json | json_query(query_cv_id) }}"

- include: get_content_view.yml

########################################################
# Publish content view
- include: publish_content_view.yml
when: sat_publish

# Getting content view another time as var is destroyed
# when skipping previous include
- include: get_content_view.yml
when: not sat_publish

########################################################
# Promote content view
- include: promote_content_view.yml
when: sat_promote

########################################################
#Remove old content views
- include: get_content_view.yml

- name: Set content view version list
set_fact:
sat_cv_version_list: "{{ sat_cv.json | json_query(query_cv_version_list) | sort(attribute='version') }}"
Expand Down
3 changes: 2 additions & 1 deletion tasks/remove_content_view.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
- name: Delete old version of content view (id is {{ sat_cv_id }}, version is {{ item.id }})
block:
- uri:
- name: Removing content view version {{ item.version }}
uri:
url: "{{ sat_url }}/v2/content_views/{{ sat_cv_id }}/remove?organization_id={{ sat_org_id }}"
method: PUT
body:
Expand Down
23 changes: 21 additions & 2 deletions tasks/update_composite_view.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
#TODO
#Get all content view inside
#for each content view inside
# get latest version ID (components[*].content_view.next_version - 1 )
# get latest version ID (version promoted to env library)
# update composite view with latest version ID
- debug: msg="NOT DONE YET, Updating Composite Content View"
- name: Initializing list of component version ids
set_fact:
sat_ccv_component_ids: []

- include: build_component_ids.yml
with_items: "{{ sat_cv.json | json_query(query_ccv_component_labels_list) }}"

- name: Update Composite Content View
uri:
url: "{{ sat_url }}/v2/content_views/{{ sat_cv_id }}"
method: PUT
body:
component_ids: "{{ sat_ccv_component_ids }}"
body_format: json
status_code: 200
user: "{{ sat_user }}"
password: "{{ sat_password }}"
validate_certs: no
force_basic_auth: yes
register: composite_content_view_update
6 changes: 5 additions & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ query_organization_id: "results[?name=='{{ sat_org }}'].id | [0]"
query_cv_id: "results[?name=='{{ sat_cv_name }}'].id | [0]"
query_cv_not_composite: "results[?composite=='false'].id | [0]"
query_cv_version_list: "versions[*].{id: id, version: version, environment_ids: environment_ids}"
query_cv_version_id: ""
query_cv_latest_version_id: "results[?id=={{ item }}].versions[*].environment_ids"

#Composite content view queries
query_ccv_component_labels_list: "components[*].content_view.label"
query_ccv_cv_version_list: "results[?label=='{{ item }}'].versions[*].{id: id, environment_ids: environment_ids} | [0]"

#Tasks queries
query_tasks_get_state: "results[?id=='{{ sat_cv_task_id }}'].state | [0]"
Expand Down

0 comments on commit 1f17686

Please sign in to comment.