tagging in ec2_elb_lb and ec2_asg :-(

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: :frowning:

In which way I can have only one tag variable definiton? How to convert ec2_tags into ec2_tags_asg?

Kind regards,
Reiner

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