Wednesday, 15 August 2012

json - Unable to fetch value from ansible_devices variable if special character in key -



json - Unable to fetch value from ansible_devices variable if special character in key -

i using gather fact variable size ansible_devices variable. host getting variable "ansible_devices": { "sda" , few server getting "ansible_devices": { "cciss!c0d0".

problem:- when using ansible variable {{ ansible_devices.sda.size }} working perfectly. when trying access value {{ ansible_devices.cciss!c0d0.size }} in playbook not returning value whereas in json ansible_devices variable there value exist {{ ansible_devices.cciss!c0d0.size }}.

{ "ansible_devices": { "cciss!c0d0": { "holders": [], "host": "raid bus controller: hewlett-packard company smart array controller (rev 03)", "model": "logical volume", "partitions": {}, "removable": "0", "rotational": "1", "scheduler_mode": "cfq", "sectors": "143299800", "sectorsize": "512", "size": "68.33 gb", "support_discard": "0", "vendor": "hp" } }, "item": "" }

it might case special character in ansible variable json key that's why unable fetch value. can suggest me how can access {{ ansible_devices.cciss!c0d0.size }} value here ?

if working in javascript , can fetch json info :

ansible_devices["cciss!c0d0"]

it display whole object under cciss!c0d0 key , can utilize inbuild function size , normally.

so seek utilize :

ansible_devices["cciss!c0d0"].size

json ansible ansible-playbook

No comments:

Post a Comment