Looking up vars from files

34 views
Skip to first unread message

Neil Saunders

unread,
Mar 30, 2015, 7:58:52 AM3/30/15
to ansible...@googlegroups.com
Hi All - 

I'm trying iterate over a list of dicts stored in an external file.

My variables file (vpc.yml) is as follows:

---
eu
-west-1:
    stage
:
       
- { name: eu-west-1a, subnet: subnet-832023ea }
       
- { name: eu-west-1b, subnet: subnet-10272479 }
       
- { name: eu-west-1c, subnet: subnet-8e2724e7 }
    live
:
       
- { name: eu-west-1a, subnet: subnet-cd340ea4 }
       
- { name: eu-west-1b, subnet: subnet-18272471 }
       
- { name: eu-west-1c, subnet: subnet-37af955e }
<snip>

And my task definition is:

---
- hosts: 127.0.0.1
  connection
: local
  vars_files
:
   
- vpc.yml


  tasks
:
   
- name: Create ASG for each zone
      ec2_asg
:
        name
: "{{ component_name }}-{{ environment }}-{{ item.name }}"
        availability_zones
: [ "{{ item.name }}" ]
        launch_config_name
: 'lc-1'
        min_size
: 1
        max_size
: 10
        desired_capacity
: 1
        vpc_zone_identifier
: [ "{{ item.subnet }}" ]
        tags
:
         
- Component: "{{ component_name }}"
         
- ComponentVersion: "{{ component_name }}"
         
- EnvLevel: "{{ environment }}"
         
- ClusterName: "{{ cluster_name }}"
         
- Country: "{{ country }}"
            propagate_at_launch
: yes
        with_items
: {{ region[environment] }}


Which I then invoke with:

ansible-playbook create-clustered-persistance-infra.yml --check -i inventory.ini --extra-vars="component_name=elasticsearch environment=stage clustername=eventsearch instance_type=m1.medium country=us region=us-east-1 component_version=9 component_ami=ami-293872"

But receive the error: 

TASK: [Create ASG for each zone] **********************************************
fatal: [127.0.0.1] => One or more undefined variables: 'item' is undefined

FATAL: all hosts have already failed -- aborting

I've tried what feels like every combination of brackets and quotes, but I'm clearly missing something.

Any assistance gratefully received.

Ta,

Neil 

Neil Saunders

unread,
Mar 30, 2015, 8:24:10 AM3/30/15
to ansible...@googlegroups.com
Ok - It appears to be an issue with the indentation level of with_items - I've dropped if back a level but an now receiving:

TASK: [Create ASG for each zone] **********************************************
fatal: [127.0.0.1] => with_items expects a list or a set

FATAL: all hosts have already failed -- aborting

Brian Coca

unread,
Mar 30, 2015, 8:33:09 AM3/30/15
to ansible...@googlegroups.com
how does region tie to eu-west-1?
> --
> 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 ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/cf098009-50db-44e5-ab24-7d2c536431a4%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Brian Coca

Neil Saunders

unread,
Mar 30, 2015, 10:10:18 AM3/30/15
to ansible...@googlegroups.com
Hi Brian - eu-west-1 is the region.

Brian Coca

unread,
Mar 30, 2015, 10:13:56 AM3/30/15
to ansible...@googlegroups.com
still, how does that become?

with_items: {{ region[environment] }}

also note that - is not a good character for variable names




--
Brian Coca
Reply all
Reply to author
Forward
0 new messages