Use Ansible variable in AWS Cloudformation template

108 views
Skip to first unread message

Tony

unread,
Oct 12, 2021, 8:04:18 AM10/12/21
to Ansible Project
Hi,

I am trying to use an ansible variable in my AWS cloudformation template, see below red where I am trying to use the variable from Ansible.

Parameters:

    Environment:
        Description: 'Environment definition.'
        Type: 'String'
        Default: 'Dev'

Resources:

    VPC:
        Type: 'AWS::EC2::VPC'
        Properties:
            CidrBlock:
                 "{{ ansible variable here }}"
            EnableDnsSupport: true
            EnableDnsHostnames: true
            InstanceTenancy: 'default'
            Tags:
                - Key: 'Environment'
                  Value:
                      Ref: 'Environment'

Does anyone know how to pass this on to Ansible?

Thank you!

Mike Eggleston

unread,
Oct 12, 2021, 8:13:36 AM10/12/21
to ansible...@googlegroups.com
$ ansible-playbook -e variable=value

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/faae7897-90bd-41c0-9966-a5e459e80686n%40googlegroups.com.

Tony

unread,
Oct 12, 2021, 8:50:59 AM10/12/21
to Ansible Project
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

Dick Visser

unread,
Oct 12, 2021, 10:26:37 AM10/12/21
to ansible...@googlegroups.com
You can let ansible generate the cloud formation template and then it will work



--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Tony

unread,
Oct 13, 2021, 10:29:30 AM10/13/21
to Ansible Project
Can you expand on that please Sir?

Dick Visser

unread,
Oct 13, 2021, 10:40:47 AM10/13/21
to ansible...@googlegroups.com
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.



Reply all
Reply to author
Forward
0 new messages