Just for reference, this is what I ended up doing:
1. in my play, I created separate vars files for each site, these 
correspond to the current host's group membership:
    - include_vars: "{{ item }}"
      with_first_found:
      - "db_{{ autogroup2 }}.yml"

2. in each var file I used the following structure:
---
  databases: 
    - 
      name: "DB1"
      primary: "Server1"
      secondaries: null
    - 
      name: "DB2"
      primary: "Server1"
      secondaries: null

3. this allowed me to access for example each db's name like so:
    - name: print stufs
      debug: msg="{{ item }}.name"
      with_items: databases

On Thursday, September 10, 2015 at 12:38:59 AM UTC+2, Trond Hindenes wrote:
>
> hm, maybe I'd be better off splitting the different location vars into 
> separate files, and then use 
>
> with_first_found
>
> I could then loop over group_names until the node found a valid variable 
> file. 
>
>
> On Thursday, September 10, 2015 at 12:25:14 AM UTC+2, Trond Hindenes wrote:
>>
>> THanks Brian. I can't seem to get this working. I can access the 
>> individual items using indexing
>> (this works: 
>> - set_fact: mybackend="{{ db[0] }}"
>> )
>> But I can't for the life of me figure out how to access by "item name" 
>> (or if that's even a valid thing in yaml). I can obviously redo the way I 
>> format the contents of my variable file, but I can't seem to strike gold. 
>> Struggling to find a good example of this in the docs/examples.
>>
>> On Thursday, September 10, 2015 at 12:12:43 AM UTC+2, Brian Coca wrote:
>>>
>>> set_fact: 
>>> mybackend="{{hostvars[inventory_hostname]['db'][varwithbackendnumber]}}" 
>>>
>>>
>>>
>>>
>>> -- 
>>> Brian Coca 
>>>
>>

-- 
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/5378711d-c930-49f0-9f3b-549fe47dbd36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to