Hey, sorry for the poor response time. It ended up being on the
'production' iteration that failed, which makes sense. The code works when
I add values for production, so its all good. Thanks for checking it over
though. Gave me confidence in debugging it. -C
On Thursday, December 31, 2015 at 8:53:02 AM UTC-8, chris meyers wrote:
>
> 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/b7afbb9f-0c31-47be-9d97-7f75d57e9a60%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.