Template each deployment file

By running each deployment file through the Ansible template module,
we're able to include ansible variables and jinja expressions in the
deployment file that will be resolved at config-download runtime.

This allows each deployment file to be more generic instead of having to
contain the hardcoded data directly out of Heat.

Change-Id: Iae9ccdf6fad2fabdce66650ee7b064f1ac9528e4
implements: blueprint reduce-deployment-resources
This commit is contained in:
James Slagle 2019-04-18 15:25:09 -04:00
parent 6c4832a7ca
commit 6b7220639a
16 changed files with 38 additions and 38 deletions

View File

@ -1,5 +1,3 @@
deploy_server_id: {{ server_id }}
{{ deployment.get('deployment_name') }}:
{% if deployment.get('scalar') %}
config: |

View File

@ -28,12 +28,27 @@
state: directory
check_mode: no
- name: "Render deployment file for {{ item }} for check-mode"
- name: "Template deployment file for {{ item }}"
template:
src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
# variable_start/end are overridden since the Heat template must be
# valid yaml, so the jinja expression must be wrapped in quotes in the
# Heat templates. Now, the extra quotes must be removed so that they do
# not end up in the final rendered value. Also, $$ is used as the delimiter
# for the jinja expression since { and } are reserved in yaml.
variable_start_string: "\"$$"
variable_end_string: "$$\""
- name: "Slurp remote deployment file for {{ item }}"
slurp:
src: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
register: deployment_content
- name: "Remote copy deployment file for {{ item }}"
copy:
content: "[ {{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item) }} ]"
dest: "/var/lib/heat-config/tripleo-config-download/check-mode/{{ item ~ '-' ~ deployment_uuid }}"
become: true
check_mode: no
content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item) }} ]"
dest: "/var/lib/heat-config/check-mode/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
- name: Run hiera deployment for check mode
shell: |
@ -98,12 +113,27 @@
- deployment_group == 'hiera'
- ansible_check_mode
- name: "Template deployment file for {{ item }}"
template:
src: "{{ tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item }}"
dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
# variable_start/end are overridden since the Heat template must be
# valid yaml, so the jinja expression must be wrapped in quotes in the
# Heat templates. Now, the extra quotes must be removed so that they do
# not end up in the final rendered value. Also, $$ is used as the delimiter
# for the jinja expression since { and } are reserved in yaml.
variable_start_string: "\"$$"
variable_end_string: "$$\""
- name: "Render deployment file for {{ item }}"
- name: "Slurp remote deployment file for {{ item }}"
slurp:
src: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}.rendered"
register: deployment_content
- name: "Remote copy deployment file for {{ item }}"
copy:
content: "[ {{ lookup('file', tripleo_role_name ~ '/' ~ ansible_hostname | lower ~ '/' ~ item) | from_yaml | json_query(item) }} ]"
content: "[ {{ deployment_content.content | b64decode | from_yaml | json_query(item) }} ]"
dest: "/var/lib/heat-config/tripleo-config-download/{{ item ~ '-' ~ deployment_uuid }}"
become: true
- name: "Check if deployed file exists for {{ item }}"
stat:

View File

@ -1,5 +1,3 @@
deploy_server_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
ControllerHostEntryDeployment:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
MyExtraConfigPost:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
MyPostConfig:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: 00b3a5e1-5e8e-4b55-878b-2fa2271f15ad
NetworkDeployment:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: a7db3010-a51f-4ae0-a791-2364d629d20d
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}

View File

@ -1,5 +1,3 @@
deploy_server_id: a7db3010-a51f-4ae0-a791-2364d629d20d
MyExtraConfigPost:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: a7db3010-a51f-4ae0-a791-2364d629d20d
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}

View File

@ -1,5 +1,3 @@
deploy_server_id: 8b07cd31-3083-4b88-a433-955f72039e2c
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}

View File

@ -1,5 +1,3 @@
deploy_server_id: 8b07cd31-3083-4b88-a433-955f72039e2c
MyExtraConfigPost:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: 8b07cd31-3083-4b88-a433-955f72039e2c
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}

View File

@ -1,5 +1,3 @@
deploy_server_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
AnsibleDeployment:
id: 391263ba-3d06-43b6-a47e-481808aaff20
creation_time: "None"

View File

@ -1,5 +1,3 @@
deploy_server_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
ComputeHostEntryDeployment:
config:
{"hiera_key1": "hiera_value1", "hiera_key2": "hiera_value2"}

View File

@ -1,5 +1,3 @@
deploy_server_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
MyExtraConfigPost:
config: |
#!/bin/bash

View File

@ -1,5 +1,3 @@
deploy_server_id: 169b46f8-1965-4d90-a7de-f36fb4a830fe
NetworkDeployment:
config:
{"hiera_key3": "hiera_value3", "hiera_key4": {"hiera_key4_subkey1": "hiera_key4_subvalue1", "hiera_key4_subkey0": "hiera_key4_subvalue0"}}