# tagging in ec2\_elb\_lb and ec2\_asg :-(

**URL:** <https://forum.ansible.com/t/tagging-in-ec2-elb-lb-and-ec2-asg/24691>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 9, 2017, 12:26pm UTC](https://forum.ansible.com/t/tagging-in-ec2-elb-lb-and-ec2-asg/24691 "2017-06-09T12:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reiner\_Nippes](https://avatars.discourse-cdn.com/v4/letter/r/91b2a8/32.png) [@Reiner\_Nippes](https://forum.ansible.com/u/Reiner_Nippes)\
**Post date:** [June 9, 2017, 12:26pm UTC](https://forum.ansible.com/t/tagging-in-ec2-elb-lb-and-ec2-asg/24691/1 "2017-06-09T12:26:18Z")

</div>

Hi,

I would like to create in AWS a loadbalancer and an auto scaling group and tag it.

The playbook looks like:

- name: Create Load Balancer  
ec2\_elb\_lb:  
name: “{{ elb\_name }}”  
state: present  
region: “{{ region }}”  
scheme: internal  
subnets: “{{ subnet\_ids }}”  
security\_group\_ids: “{{ elb\_secgrp }}”  
idle\_timeout: 3600  
listeners:

- protocol: tcp  
load\_balancer\_port: 22  
instance\_port: 22  
tags: “{{ ec2\_tags }}”

- name: Create Autoscaling Group  
ec2\_asg:  
name: “{{ asg\_name }}”  
launch\_config\_name: “{{ lc\_name }}”  
health\_check\_period: 300  
health\_check\_type: EC2  
replace\_all\_instances: yes  
load\_balancers: “{{ elb\_name }}”  
min\_size: 1  
max\_size: 1  
desired\_capacity: 1  
region: “{{ region }}”  
vpc\_zone\_identifier: “{{ subnet\_ids }}”  
tags: “{{ ec2\_tags\_asg }}”

As you can see I put the tags in variables because they depend on the vpc of the lb/asg.

ec2\_tags:  
{ “Name”:“BlaBla”,  
“ApplicationName”:“n/a”,  
“ApplicationID”:“n/a” }

ec2\_tags\_asg:  
[ “Name”:“BlaBla”,  
“ApplicationName”:“n/a”,  
“ApplicationID”:“n/a” ]

But for an unknown reason the guy how programmed the ec2\_asg module thought it’s OK to use another variable type then the rest of the aws/ec2 modules: ☹

In which way I can have only one tag variable definiton? How to convert ec2\_tags into ec2\_tags\_asg?

Kind regards,  
Reiner

---

<div class="post-metadata">

**Author:** ![stephan.schaarschmid](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@stephan.schaarschmid](https://forum.ansible.com/u/stephan.schaarschmid)\
**Post date:** [July 21, 2017, 7:29am UTC](https://forum.ansible.com/t/tagging-in-ec2-elb-lb-and-ec2-asg/24691/2 "2017-07-21T07:29:19Z")

</div>

The solution for you is to use your variable ec2\_tags as list entry with the module ec2\_asg.  
This looks like this (rest of the arguments not shown):

- name: Create Load Balancer  
ec2\_elb\_lb:  
name: “{{ elb\_name }}”  
#other args  
tags: “{{ ec2\_tags }}”

- name: Create Autoscaling Group  
ec2\_asg:  
name: “{{ asg\_name }}”  
#other args  
tags:

- “{{ ec2\_tags }}”

That’s the way it works for me.

Cheers, Stephan
