Skip to content

Commit

Permalink
Add support for remote Jinja templates (#140)
Browse files Browse the repository at this point in the history
* Add support for remote Jinja templates

* Remove spurious whitespace
  • Loading branch information
pabrahamsson authored and oybed committed Aug 13, 2019
1 parent 4c2bd5f commit 716c73c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
26 changes: 22 additions & 4 deletions roles/openshift-applier/tasks/process-jinja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,32 @@

- name: Set processed Jinja template output path
set_fact:
dest_path: "{{ jinja_tmp_dir.path }}/processed_{{ lookup('vars', process_file_or_template) | basename | regex_replace('.j2$','.yml') }}"
dest_path_yml: "{{ jinja_tmp_dir.path }}/processed_{{ lookup('vars', process_file_or_template) | basename | regex_replace('.j2$','.yml') }}"
dest_path_j2: "{{ jinja_tmp_dir.path }}/{{ lookup('vars', process_file_or_template) | basename }}"

- name: Determine Jinja template location
set_fact:
template_location: "{{ lookup('vars', process_file_or_template) | check_file_location }}"

- name: Copy Jinja template locally if remote
get_url:
url: "{{ lookup('vars', process_file_or_template) }}"
dest: "{{ dest_path_j2 }}"
when: not template_location.local_path

- name: Copy Jinja template to temp dir if local
local_action:
module: copy
src: "{{ lookup('vars', process_file_or_template) }}"
dest: "{{ dest_path_j2 }}"
when: template_location.local_path

- name: Process Jinja template
template:
src: "{{ lookup('vars', process_file_or_template) }}"
dest: "{{ dest_path }}"
src: "{{ dest_path_j2 }}"
dest: "{{ dest_path_yml }}"

- name: Update path
set_fact: {"{{ process_file_or_template }}":"{{ dest_path }}"}
set_fact: {"{{ process_file_or_template }}":"{{ dest_path_yml }}"}

delegate_to: localhost
7 changes: 4 additions & 3 deletions tests/inventories/jinja-templates/group_vars/seed-hosts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@ environments:
- dev
- test
- prod

namespace_metadata:
NAMESPACE: oa-ci-jinja-templates
NAMESPACE_DISPLAY_NAME: OpenShift Applier Jinja Templates Test 1 (displayName)
NAMESPACE_DESCRIPTION: OpenShift Applier Jinja Templates Test 1 (description)
openshift_applier_raw: "https://raw.githubusercontent.com/redhat-cop/openshift-applier"
openshift_applier_ver: v2.1.0

openshift_cluster_content:
- object: projectrequest
content:
- name: jinja-project-test-template
template: "{{ inventory_dir }}/../../files/jinja-templates/projectrequest_template.j2"
template: "{{ openshift_applier_raw }}/{{ openshift_applier_ver }}/tests/files/jinja-templates/projectrequest_template.j2"
params_from_vars: "{{ namespace_metadata }}"
action: create
- name: jinja-project-test-file
file: "{{ inventory_dir }}/../../files/jinja-templates/projectrequest_file.j2"
action: create
- name: delete jinja-project-test-template
template: "{{ inventory_dir }}/../../files/jinja-templates/projectrequest_template.j2"
template: "{{ openshift_applier_raw }}/{{ openshift_applier_ver }}/tests/files/jinja-templates/projectrequest_template.j2"
params_from_vars: "{{ namespace_metadata }}"
action: delete
- name: delete jinja-project-test-file
Expand Down

0 comments on commit 716c73c

Please sign in to comment.