# How to convert the cloudformation template\_url parameter to be the Jinja template substitution

**URL:** <https://forum.ansible.com/t/how-to-convert-the-cloudformation-template-url-parameter-to-be-the-jinja-template-substitution/29490>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [January 22, 2019, 12:32pm UTC](https://forum.ansible.com/t/how-to-convert-the-cloudformation-template-url-parameter-to-be-the-jinja-template-substitution/29490 "2019-01-22T12:32:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kishore\_Ponniah](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@Kishore\_Ponniah](https://forum.ansible.com/u/Kishore_Ponniah)\
**Post date:** [January 22, 2019, 12:32pm UTC](https://forum.ansible.com/t/how-to-convert-the-cloudformation-template-url-parameter-to-be-the-jinja-template-substitution/29490/1 "2019-01-22T12:32:02Z")

</div>

Hi All,

The cloudformation template\_url parameter requires Amazon S3 URL which is currently working by providing the complete URL of the file. But I wanted to convert that to be the Jinja template substitution.

My playbook below:

- name: create ps-cross-account-roles changeset  
cloudformation:  
stack\_name: “ps-cross-account-roles”  
state: present  
region: “{{ account\_config.1 }}”  
aws\_access\_key: “{{ account\_config.0.sts\_creds.access\_key }}”  
aws\_secret\_key: “{{ account\_config.0.sts\_creds.secret\_key }}”  
security\_token: “{{ account\_config.0.sts\_creds.session\_token }}”  
create\_changeset: true  
changeset\_name: “{{ cf\_changeset\_name }}”

# Don’t pass the cd-deploy-role to CF due to [possible privilege escalation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-servicerole.html)

# for anyone able to perform stack updates.

# role\_arn: “{{ account\_config.0.account\_config.pass\_role\_arn }}”

template\_url: “[https://s3-eu-west-1.amazonaws.com/xxxxxxxxxxx/cloudformation/xxxxxxxxxxxx/ps-cross-account-roles.yaml](https://s3-eu-west-1.amazonaws.com/xxxxxxxxxxx/cloudformation/xxxxxxxxxxxx/ps-cross-account-roles.yaml)”  
template\_parameters: “{{ account\_config.0.account\_config.stacks[‘ps-cross-account-roles’].params }}”  
termination\_protection: no  
tags: “{{ global\_tags | combine(account\_config.0.account\_config.stacks[‘ps-cross-account-roles’].override\_tags, recursive=True) }}”

# Convert to a list of dicts duplicated per region. See [https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_filters.html#subelements-filter](https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#subelements-filter)

loop: “{{ assumed\_roles\_with\_account\_config.results|subelements(‘account\_config.regions’, skip\_missing=True) }}”  
loop\_control:  
loop\_var: account\_config  
label: “{{ account\_config.0.account\_config.account\_alias }}:{{ account\_config.1 }}”  
tags:  
rxgt-ps-identity-stack-deploy

build\_account:  
account\_alias: xxxxxxx  
sts\_role\_arn: arn:aws:iam::xxxxxxxxxxx:role/xxxx/xx/cd-deploy-role  
pass\_role\_arn: “”

account\_config:  
s3\_sync:  
params:  
region: eu-west-1  
bucket: xxxxxxxxxxxxxxx  
file\_root: files/  
key\_prefix: cloudformation/xxxxxx/  
mode: push  
file\_change\_strategy: date\_size  
permission: private  
include: “_.yaml,_.json”

How to convert the template\_url to jinja template substitution?

template\_url: “{{ build\_account.account\_config.s3\_sync.params.bucket }}”

Can someone please advise?

Thanks  
Kishore

---

<div class="post-metadata">

**Author:** ![Kishore\_Ponniah](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@Kishore\_Ponniah](https://forum.ansible.com/u/Kishore_Ponniah)\
**Post date:** [January 22, 2019, 4:50pm UTC](https://forum.ansible.com/t/how-to-convert-the-cloudformation-template-url-parameter-to-be-the-jinja-template-substitution/29490/2 "2019-01-22T16:50:02Z")

</div>

Hi all,

This is resolved by using template\_url: “[https://s3.amazonaws.com/](https://s3.amazonaws.com/){{ build\_account.account\_config.s3\_sync.params.bucket }}/{{ build\_account.account\_config.s3\_sync.params.key\_prefix }}ps-cross-account-iam-roles.yaml”

Regards  
Kishore
