implementing hashes

37 views
Skip to first unread message

Brandon Metcalf

unread,
Jul 19, 2014, 7:52:29 AM7/19/14
to ansible...@googlegroups.com
It seems this should work according to the docs.  It does work if I use

with_items: app1


$ cat jj.yml
---
- hosts: all

  vars:
    app1:
      - base: "{{ file | basename }}"

    app2:
      - base: "{{ file }}"

  tasks:
      - name: debug
        debug: msg="{{ item.base }}"
        with_items:
          - app1
          - app2

$ ansible-playbook ./jj.yml -i hosts --extra-vars 'file=/tmp/jj'
...
TASK: [debug] *****************************************************************
fatal: [myhost] => One or more undefined variables: 'str' object has no attribute 'base'

What am I doing wrong?  Thanks.

Michael DeHaan

unread,
Jul 19, 2014, 8:00:10 AM7/19/14
to ansible...@googlegroups.com
In the above, app1 and app2 are not hashes, but lists of strings.

I think you would want to define them like:

app2: { base: "foo" }

etc

But really probably

apps:
   - { name: app1, base: foo }
   - { name: app2, base: bar }

tasks:
   - blarg: ...
     with_items: apps

Etc.

Let me know if you'd like more detail on some of the above, but that should get you started.


--
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/CABdN8i05KDF%2BdO0y%2B8ZApsixbqdCfrtrRjf9vwxeZ0hJ87Ueeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Metcalf

unread,
Jul 21, 2014, 10:15:01 AM7/21/14
to ansible...@googlegroups.com
Thanks, Michael.   I was able to get something like that working.  However, what I ultimately need is the ability to control the order in which app1 and app2 are operated on within certain tasks.  For some tasks, I need to operate on app1 first and for others app2 first.



For more options, visit https://groups.google.com/d/optout.



--
Brandon Metcalf | Technical Operations


Cloud-based performance monitoring

  

Michael DeHaan

unread,
Jul 21, 2014, 7:14:45 PM7/21/14
to ansible...@googlegroups.com
You could still keep the data in the hash and then traverse an array.

thing_details[item]['hash_key']

where thing_details is a hash

and you're traversing across a with_items: thing_names





Reply all
Reply to author
Forward
0 new messages