Dynamic Variables

Hi i’m able to create dynamic facts but i have a problem using them in other task

i set the facts like this:

  • name: set security_groups facts
    set_fact:
    “{{ item.item.name | replace(‘-’, ‘_’) }}_group”:
    name: “{{ item.item.name }}”
    group_id: “{{ item.group_id }}”
    rules: “{{ item.item.rules }}”
    state: “{{ item.item.state }}”
    with_items: ec2_groups.results

and are accessible calling like this

  • debug: var=monitor_server_group
  • debug: var=monitor_test_1_group
  • debug: var=monitor_test_2_group

but when i try to do this

  • name: Create EC2 instances per subnets
    ec2:
    profile: “{{ boto_profile }}”
    key_name: “{{ item[1].name }}”
    region: “{{ vpc.region }}”
    group_id: “{{ item[1].name | replace(‘-’, ‘_’) ~ ‘_group’ }}.group_id”
    instance_type: “{{ item[1].instance_type }}”
    image: “{{ item[1].ami }}”
    vpc_subnet_id: “{{ item[0] }}”
    monitoring: yes
    wait: yes
    instance_tags:
    env: “{{ linio_environment }}”
    Name: “{{ item[1].name }}”
    role: “{{ item[1].role }}”
    group: “{{ item[1].host_group }}”
    cap_stage: “{{ item[1].role }}”
    count_tag: “{{ item[1].name }}”
    exact_count: “{{ item[1].instances }}”
    with_nested:
  • vpc.subnets.security.private_subnet_ids
  • ec2_instances_configuration
    register: api_instances_facts

i got:

InvalidGroupId.MalformedInvalid id: “monitor_test_2_group.group_id”

how can i use the name as variable object instead of a string