Ansible playbook --extra-var with dot in json key

591 views
Skip to first unread message

Foss Geek

unread,
Feb 23, 2018, 6:22:35 AM2/23/18
to Ansible Project

Hi All,

I need to pass a json file to ansible-palybook command using --extra-var (like --extra-var @/tmp/test.json).  I am able to reference the variable inside playbook if the json key don't have dot character in it.  But I am not able reference the key which contain dot(.) in it. This is just sample entry in JSOn file but I have many keys which contain dot(.) in key name and I can't remove the dot char in the key name because the file coming from external system. 

# cat /tmp/test.json | jq
{
  "VMware.Hardware.Version": " vmx-10",
  "toolname": "tomcat"
}

Playbook:

# cat test.yml 
---
host: myhost
vars:
  hdversion: "{{ VMware.Hardware.Version }}" # not works due to dot(.), getting VARIABLE NOT DEFINED when try to reference hdversion inside role
  mytoolname: "{{toolname}}"  # works fine

any workaround to use hdversion: "{{ VMware.Hardware.Version }}" to get the value? 
Any advise or guidance would be greatly appreciated.

Kai Stian Olstad

unread,
Feb 23, 2018, 6:36:39 AM2/23/18
to ansible...@googlegroups.com
On 23.02.2018 12:22, Foss Geek wrote:
> # cat /tmp/test.json | jq
> {
> "VMware.Hardware.Version": " vmx-10",
>
> "toolname": "tomcat"
>
> }
>
>
> Playbook:
>
>
> # cat test.yml
>
> ---
>
> host: myhost
>
> vars:
>
> hdversion: "{{ VMware.Hardware.Version }}" # not works due to
> dot(.), getting VARIABLE NOT DEFINED when try to reference hdversion
> inside role
>
> mytoolname: "{{toolname}}" # works fine
>
>
> any workaround to use hdversion: "{{ VMware.Hardware.Version }}" to
> get the value?
>
> Any advise or guidance would be greatly appreciated.

This should work
{{ vars['VMware.Hardware.Version'] }}


--
Kai Stian Olstad

Foss Geek

unread,
Feb 23, 2018, 6:57:38 AM2/23/18
to Ansible Project
Oh. That helps. Thank you very much. 
Reply all
Reply to author
Forward
0 new messages