Complex dictionary access

16 views
Skip to first unread message

Mark Tovey

unread,
Apr 25, 2019, 2:36:42 PM4/25/19
to Ansible Project


    I have a dictionary structure that looks like the following:
  
myservers:
DC1:
CORE: 10.10.10.20
DMZ: 10.10.20.20
DC2:
CORE: 10.10.10.30.20
DMZ: 10.10.10.40.20
DC3:
CORE: 10.10.50.20
DMZ: 10.10.60.20
DC4:
CORE: 10.10.70.20
DMZ: 10.10.80.20

    And another dictionary that looks like the following:

location:
address: 10.10.10.10
dc: DC1
net: 10.10.10.0
bits: 24
zone: CORE 

    I want to do something like the following:

- debug:
msg: "myserver = myservers['{{location.dc}}']['{{location.zone}}']"

    and get back the message:

myserver = 10.10.10.20

    But instead, I get:

myserver = myservers['DC1']['CORE']
 
    I want to see the value stored at myservers['DC1']['CORE'], not the string "myservers['DC1']['CORE']".

    I have tried " {{ myservers['{{location.dc}}']['{{location.zone}}] }}", but YAML does not allow nested braces, so that fails.  And I have tried many other variations, but they all fail too.  I am stymied.  How do I extract the information I want?



 
 
 

Алексей Смирнов

unread,
Apr 25, 2019, 2:50:00 PM4/25/19
to ansible...@googlegroups.com
Hello.
Try use "{{myserver[location.dc][location.zone]}}"


пт, 26 апр. 2019 г., 1:36 'Mark Tovey' via Ansible Project <ansible...@googlegroups.com>:
--
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/0cb211b9-7c67-4b5a-b04b-2cd66db2fd24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mark Tovey - DSV

unread,
Apr 25, 2019, 3:37:00 PM4/25/19
to ansible...@googlegroups.com

 

    I knew it was going to be simple, although I thought I tried that one too.  But that got it.

    Thanks!

  

 

 

--------------------------------------------------------------------------------------------------------------------------

Description: cid:image001.gif@01D09EC0.4CEB1A90Mark Tovey - UNIX Engineer

DSV | 110 N Marine Dr. | Bldg 1 | Portland | Oregon | 97217 | USA

Mark...@dsv.com | +1 503 222-5546

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/bLYL1SGByK4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.


To post to this group, send email to ansible...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages