# Dynamic Variables

**URL:** <https://forum.ansible.com/t/dynamic-variables/20819>\
**Category:** Ansible Project\
**Created:** [March 9, 2016, 11:31pm UTC](https://forum.ansible.com/t/dynamic-variables/20819 "2016-03-09T23:31:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rodolfo\_Gonzalez\_Rom](https://avatars.discourse-cdn.com/v4/letter/r/e9a140/32.png) [@Rodolfo\_Gonzalez\_Rom](https://forum.ansible.com/u/Rodolfo_Gonzalez_Rom)\
**Post date:** [March 9, 2016, 11:31pm UTC](https://forum.ansible.com/t/dynamic-variables/20819/1 "2016-03-09T23:31:24Z")

</div>

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.Malformed`Invalid id: “monitor\_test\_2\_group.group\_id”

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