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/caa082cf-608a-41fb-a91b-fc77c7d48216%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to