Colin,
The logic and code looks good to me. Maybe there is a spelling or similar
simple error. Can you post everything? Also, can you get more specific with
the error (i.e. what iteration it's failing on).
On Tuesday, December 29, 2015 at 6:01:40 PM UTC-6, Colin Byrne wrote:
>
> Hey so I am trying to loop through a dictionary list of servers I want to
> create, and want to evaluate some variables based on the iteration I am on.
> I am not sure if I has a syntax error or I am trying something not
> supported by ansible, or if it's caused by the dictionary not being
> evaluated at that point yet:
>
> ---
>
> - name: Launch instances based on server list
>
> ec2:
>
> key_name: "{{ server_type[item.key].key_name }}"
>
> group_id: "{{ server_type[item.key].security_group }}"
>
> instance_type: "{{ server_type[item.key].instance_type }}"
>
> image: "{{ server_type[item.key].image }}"
>
> wait: false
>
> region: "{{ server_type[item.key].region }}"
>
> instance_tags:
>
> Type: "{{ item.key }}"
>
> Name: integ-{{ item.value.name }}
>
> exact_count: 1 #dont change!
>
> count_tag:
>
> Name: integ-{{ item.value.name }}
>
> vpc_subnet_id: subnet=blah
>
> assign_public_ip: no
>
> register: ec2
>
> with_dict: "{{ servers }}"
>
> Then I have a dictionary and another list in my /role/vars/main.yml
>
> ---
>
>
> server_type:
>
> integ:
>
> security_groups: ['sg-81398ee4', 'sg-a6398ec3']
>
> image: ami-xxxxxx
>
> instance_type: t2.medium #needs to match the base image size
>
> region: us-west-1
>
> key_name: joeypeters
>
> production:
>
> mysql:
>
>
> servers:
>
> integ:
>
> name: joey
>
> # name: bob
>
> production:
>
> mysql:
>
>
> ...
>
>
> I get the following error:
>
>
> fatal: [localhost] => One or more undefined variables: 'None' has no
> attribute 'instance_type'
>
>
> FATAL: all hosts have already failed -- aborting
>
>
> I am up for structuring it entirely different if necessary.
>
>
> Thanks a lot for the help.
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5a5f77fd-f5a7-4c66-860e-bc54a3dca34b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.