# Use Ansible variable in AWS Cloudformation template

**URL:** <https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852>\
**Category:** Ansible Project\
**Tags:** ansible-project, aws\
**Created:** [October 12, 2021, 12:12pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852 "2021-10-12T12:12:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Eggleston](https://avatars.discourse-cdn.com/v4/letter/m/58956e/32.png) [@Mike\_Eggleston](https://forum.ansible.com/u/Mike_Eggleston)\
**Post date:** [October 12, 2021, 12:12pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852/1 "2021-10-12T12:12:29Z")

</div>

$ ansible-playbook -e variable=value

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [October 12, 2021, 12:50pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852/2 "2021-10-12T12:50:59Z")

</div>

Sorry I think you may have misunderstood what I am trying to accomplish.

I need to pass an ansible variable to a cloudformation template yml file.

I believe I need to do some form of templating with j2, but looking for pointers.

Thanks

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 12, 2021, 2:26pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852/3 "2021-10-12T14:26:06Z")

</div>

You can let ansible generate the cloud formation template and then it will work

---

<div class="post-metadata">

**Author:** ![Tony1](https://avatars.discourse-cdn.com/v4/letter/t/858c86/32.png) [@Tony1](https://forum.ansible.com/u/Tony1)\
**Post date:** [October 13, 2021, 2:29pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852/4 "2021-10-13T14:29:30Z")

</div>

Can you expand on that please Sir?

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 13, 2021, 2:40pm UTC](https://forum.ansible.com/t/use-ansible-variable-in-aws-cloudformation-template/35852/5 "2021-10-13T14:40:21Z")

</div>

You can use ansible to generate the cloudformation template, so you can use any variables from your ansible inventory/vars/etc.  
For instance using a ‘template’ task.  
Then once that is done, the result can by used by cloudformation.

I have no idea how this may (or may not) fit into whatever work flow you have.
