Skip to content

Commit

Permalink
Fix to allow late variable evaluation (#138)
Browse files Browse the repository at this point in the history
This allows variables set by set_fact called in a previous content items to be
referenced in later content items.
  • Loading branch information
jkupferer authored and oybed committed Aug 7, 2019
1 parent f4d8f5e commit 4c2bd5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
28 changes: 11 additions & 17 deletions roles/openshift-applier/filter_plugins/applier-filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_invalid_tag_usage(applier_list, include_tags, exclude_tags):
return repeated_tags


# Helper function to simplify the 'filter_applier_items' below
# Helper function to simplify the 'filter_applier_item' below
def filter_content(content_dict, outer_list, include_list, exclude_list):
# Handle if tags don't exist in the 'content' section
if 'tags' not in content_dict:
Expand All @@ -69,11 +69,11 @@ def filter_content(content_dict, outer_list, include_list, exclude_list):
return


# Main 'filter_applier_items' function
def filter_applier_items(applier_list, include_tags, exclude_tags):
# If no tag lists supplied - just return list as-is
# Main 'filter_applier_item' function
def filter_applier_item(applier_item, include_tags, exclude_tags):
# If no tag lists supplied - just return item
if len(include_tags.strip()) == 0 and len(exclude_tags.strip()) == 0:
return applier_list
return applier_item

exclude_list, include_list = [], []

Expand All @@ -86,18 +86,12 @@ def filter_applier_items(applier_list, include_tags, exclude_tags):
exclude_list = exclude_tags.split(",")
exclude_list = [i.strip() for i in exclude_list]

# Loop through the main list to check tags
# - use a copy to allow for elements to be removed at the same time as we iterrate
for a in applier_list[:]:
# Handle the 'content' entries
if 'content' in a:
for c in a['content'][:]:
filter_content(c, a['content'], include_list, exclude_list)

if len(a['content']) == 0:
applier_list.remove(a)
# Handle the 'content' entries
if 'content' in applier_item:
for c in applier_item['content'][:]:
filter_content(c, applier_item['content'], include_list, exclude_list)

return applier_list
return applier_item


# Function used to determine a files location - i.e.: URL, local file/directory or "something else"
Expand Down Expand Up @@ -142,6 +136,6 @@ class FilterModule(object):
def filters(self):
return {
'check_file_location': check_file_location,
'filter_applier_items': filter_applier_items,
'filter_applier_item': filter_applier_item,
'get_invalid_tag_usage': get_invalid_tag_usage
}
7 changes: 4 additions & 3 deletions roles/openshift-applier/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

- name: "Create OpenShift objects"
include_tasks: process-content.yml
with_items:
- "{{ openshift_cluster_content | filter_applier_items(include_tags, exclude_tags) | default([]) }}"
with_items: "{{ range(0, openshift_cluster_content|default([])|length) | list }}"
loop_control:
loop_var: entry
loop_var: entry_n
vars:
entry: "{{ openshift_cluster_content[entry_n] }}"
when:
- entry.content is defined
2 changes: 1 addition & 1 deletion roles/openshift-applier/tasks/process-content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- name: "Create/Apply OpenShift Cluster Content ('{{ entry.object }}') - based on individual files"
include_tasks: process-one-entry.yml
with_items:
- "{{ entry.content | default([]) }}"
- "{{ (entry | filter_applier_item(include_tags, exclude_tags)).content | default([]) }}"
loop_control:
loop_var: content

Expand Down

0 comments on commit 4c2bd5f

Please sign in to comment.