Python 使用ansible时如何从dict获取值返回

Python 使用ansible时如何从dict获取值返回,python,ansible,jinja2,Python,Ansible,Jinja2,我计划最近通过ansible调用vRA api。我可以从API use uri模式获取json结果返回。但是,在将请求发布到API之前,如何获取id的“重新启动计算机”值(“07831a32-0bc7-4f7d-8372-164ea69d61af”) 这里的逻辑是首先循环内容项,然后保存id.value(“07831a32-0bc7-4f7d-8372-164ea69d61af”)以在匹配关键字时注册(重新启动机器) 然而,代码并不像我期望的那样工作 有人能帮我提些建议吗。如何处理这个问题 -

我计划最近通过ansible调用vRA api。我可以从API use uri模式获取json结果返回。但是,在将请求发布到API之前,如何获取id的“重新启动计算机”值(“07831a32-0bc7-4f7d-8372-164ea69d61af”)

这里的逻辑是首先循环内容项,然后保存id.value(“07831a32-0bc7-4f7d-8372-164ea69d61af”)以在匹配关键字时注册(重新启动机器)

然而,代码并不像我期望的那样工作

有人能帮我提些建议吗。如何处理这个问题

- name: get actions list
  uri: xxxxxxx
      ......
  register: actions


- name: var_aaa
  when: actions.json.content[{{ item }}]['description'] == "Delete a snapshot of this machine."
  with_sequence: start=0 end={{ (actions.json.content|count) -1 }}
  register: actions.json.content[{{ item }}]['id']
下面是示例json

/

我使用任务的“block”来获得“id”的值,所以在block下创建一个任务,这样您就可以在块内的所有任务中使用id的值

tasks:
 - name: Getting actions list
   block: 
    - name: get actions list
      uri: xxxxxxx
      ......
      register: actions

    - name: Saving the id value in the variable id
      set_fact:
        id={{ item.id }}
      when: "'Power off a machine' in item.description"
      with_items:
       "{{ actions.json.content }}"
    - name: Printing the Value of id
      debug: var=id
tasks:
 - name: Getting actions list
   block: 
    - name: get actions list
      uri: xxxxxxx
      ......
      register: actions

    - name: Saving the id value in the variable id
      set_fact:
        id={{ item.id }}
      when: "'Power off a machine' in item.description"
      with_items:
       "{{ actions.json.content }}"
    - name: Printing the Value of id
      debug: var=id