如何在带有json寄存器的ansible playbook中使用嵌套循环
我从一个rb中得到一个复杂的json,我像这样注册如何在带有json寄存器的ansible playbook中使用嵌套循环,json,ansible,ansible-playbook,Json,Ansible,Ansible Playbook,我从一个rb中得到一个复杂的json,我像这样注册 - name: get the json command: /abc/get_info.rb register: JsonInfo {"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":[["0000000
- name: get the json
command: /abc/get_info.rb
register: JsonInfo
{"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"]]}
- debug: msg="{{item.key}} and the host is{{inventory_hostname}} and value is{{item.value}}"
with_dict: "{{JsonInfo.stdout}}"
when: item.key==inventory_hostname
json是这样的
- name: get the json
command: /abc/get_info.rb
register: JsonInfo
{"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"]]}
- debug: msg="{{item.key}} and the host is{{inventory_hostname}} and value is{{item.value}}"
with_dict: "{{JsonInfo.stdout}}"
when: item.key==inventory_hostname
但我能做的就是像这样输出json:
- debug: msg="{{JsonInfo}}"
然后像这样循环
- name: get the json
command: /abc/get_info.rb
register: JsonInfo
{"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"]]}
- 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"]]
当我得到以上所有这些,我对a-b-c.abc.com,c-d-e.abc.com,c-d-m.abc.com的每个值运行另一个循环,然后根据“a”,“c”,在a-b-c.abc.com或c-d-e.abc.com上运行不同的命令
我如何循环那些json?这是不可能的。您可以通过将其存档