-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add support for Jinja templates, closes #119 * Use project.openshift.io/v1 * Remove unsupported '--validate' param from 'delete' action * Set correct params for patch, delete & get * Don't use '--ignore-not-found' with patch * Hold off on 'oc get' for #134
- Loading branch information
1 parent
18b0821
commit 1b87b99
Showing
11 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
|
||
- name: Delegate processing to localhost | ||
block: | ||
- name: Set file or template fact | ||
set_fact: | ||
process_file_or_template: "{{ (file != '') | ternary('file', 'template') }}" | ||
|
||
- name: Create temporary directory for Jinja template output | ||
tempfile: | ||
state: directory | ||
register: jinja_tmp_dir | ||
notify: | ||
- Clean up temporary Jinja directory | ||
|
||
- 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') }}" | ||
|
||
- name: Process Jinja template | ||
template: | ||
src: "{{ lookup('vars', process_file_or_template) }}" | ||
dest: "{{ dest_path }}" | ||
|
||
- name: Update path | ||
set_fact: {"{{ process_file_or_template }}":"{{ dest_path }}"} | ||
|
||
delegate_to: localhost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: List | ||
items: | ||
{% for environment in environments %} | ||
- apiVersion: project.openshift.io/v1 | ||
kind: {{ 'Project' if (oc_action == 'delete') else 'ProjectRequest' }} | ||
metadata: | ||
name: {{ namespace_metadata.NAMESPACE }}-file-{{ environment }} | ||
description: {{ namespace_metadata.NAMESPACE_DESCRIPTION }} (file) - {{ environment }} | ||
displayName: {{ namespace_metadata.NAMESPACE_DISPLAY_NAME }} (file) - {{ environment }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Template | ||
labels: | ||
template: projectrequest-template | ||
message: |- | ||
The following project/namespace has been created: ${NAMESPACE} | ||
metadata: | ||
annotations: | ||
description: |- | ||
ProjectRequest Template | ||
creationTimestamp: null | ||
name: ${NAMESPACE} | ||
objects: | ||
{% for environment in environments %} | ||
- apiVersion: project.openshift.io/v1 | ||
kind: {{ 'Project' if (oc_action == 'delete') else 'ProjectRequest' }} | ||
metadata: | ||
name: ${NAMESPACE}-template-{{ environment }} | ||
description: '${NAMESPACE_DESCRIPTION} (template) - {{ environment }}' | ||
displayName: '${NAMESPACE_DISPLAY_NAME} (template) - {{ environment }}' | ||
{% endfor %} | ||
parameters: | ||
- description: Name | ||
displayName: Name | ||
name: NAMESPACE | ||
required: true | ||
- description: DisplayName | ||
displayName: DisplayName | ||
name: NAMESPACE_DISPLAY_NAME | ||
required: true | ||
- description: Description | ||
displayName: Description | ||
name: NAMESPACE_DESCRIPTION |
29 changes: 29 additions & 0 deletions
29
tests/inventories/jinja-templates/group_vars/seed-hosts.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
|
||
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_cluster_content: | ||
- object: projectrequest | ||
content: | ||
- name: jinja-project-test-template | ||
template: "{{ inventory_dir }}/../../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" | ||
params_from_vars: "{{ namespace_metadata }}" | ||
action: delete | ||
- name: delete jinja-project-test-file | ||
file: "{{ inventory_dir }}/../../files/jinja-templates/projectrequest_file.j2" | ||
action: delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
|
||
ansible_connection: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
[seed-hosts] | ||
localhost |