parameterized role and with_dict loop

434 views
Skip to first unread message

ro...@pandastrike.com

unread,
Dec 1, 2014, 3:03:04 PM12/1/14
to ansible...@googlegroups.com



I have a role, route53-healthcheck, which execute a series of command: tasks using the aws cli (Ansible route53 module is for DNS records-only).

I have a dictionary of Application names and metadata in group_vars/all. I want am trying to loop over the dictionary using with_dict calling the roll each time with different parameters:

route53-healthchecks.yml
---
# create Route53 Health check and CloudWatch Alarm
- name: Route53 Health Checks for all Apps
  hosts: webservers[0]
  connection: local
  gather_facts: no
  roles:
    - { role: route53-healthcheck,
          app: '{{ item.key }}' ,
          app_domain: '{{ app_host }}',
          fqdn: '{{ item.key }}-{{ app_environment }}.{{ app_host }}',
        with_dict: apps }


I am getting an error that 'item' is undefined:


$ ansible-playbook -vvv -i staging route53-healthcheck.yml

PLAY [Route53 Health Checks for all Apps] *************************************

TASK: [route53-healthcheck | Route53 Caller Reference for this Health Check] ***
fatal: [web-1.us-east-1.example.com] => One or more undefined variables: 'item' is undefined

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/home/ubuntu/route53-healthcheck.retry

web-1.us-east-1.example.com : ok=0    changed=0    unreachable=1    failed=0


What is the proper way to loop through calling roles?

Thanks,
Robb

Michael DeHaan

unread,
Dec 1, 2014, 5:14:23 PM12/1/14
to ansible...@googlegroups.com
Roles cannot be presently used with iterators.  This is something the 'v2/' subtree may allow at a later date.

Until then, the solution is to apply the loop to each task inside the role that needs to be looped.



--
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/ae023bb8-226f-456f-be49-99af5840aedb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages