我从rb获得了一个复杂的json,我就像这样注册
- name: get the json
command: /abc/get_info.rb
register: JsonInfo
和json是这样的
{"a-b-c.abc.com":[["000000001","a"],["000000002","a"],["000000003","c"]],"c-d-e.abc.com":[["000000010","c"],["000000012","b"]],"c-d-m.abc.com":[["000000022","c"],["000000033","b"],["000000044","c"]]}
但我能做的就是像这样输出json:
- debug: msg="{{JsonInfo}}"
并像这样循环
- debug: msg="{{item.key}} and the host is{{inventory_hostname}} and value is{{item.value}}"
with_dict: "{{JsonInfo.stdout}}"
when: item.key==inventory_hostname
<顺便说一下,a-b-c.abc.com,c-d-e.abc.com,c-d-m.abc.com是服务器的主机名
但我真正想做的是先在json上运行一个循环,然后得到
的结果"a-b-c.abc.com":[["000000001","a"],["000000002","a"],["000000003","c"]]
"c-d-e.abc.com":[["000000010","c"],["000000012","b"]]
"c-d-m.abc.com":[["000000022","c"],["000000033","b"],["000000044","c"]]
当我得到上述所有内容后,我为abc.abc.com,cde.abc.com,cdm.abc.com的每个值运行另一个循环,然后根据&#34; a&#34 ;,&#34; C&#34; ,在a-b-c.abc.com或c-d-e.abc.com上运行不同的命令
我如何循环这些json?