首页 > 解决方案 > 无法从具有较旧 ansible 版本和 python 2.x 的 rhel 机器访问 json

问题描述

我正在使用 uri 模块对 api 执行相同的请求/任务。当我在 python 3.7.1 和 ansible 2.8.1 上从 mac 执行时,它可以工作。当我从带有 python 2.7.5 和 ansible 2.4.2.0 的 red hat linux 机器上执行时,它不起作用,我得到了错误'dict object' has no attribute 'json'

这是具有虚拟值的任务:

  - name: get request
    uri:
      url: https://url.com{{ foo }}
      method: GET
      user:  user
      validate_certs: False
      password: password
      return_content: yes
      body_format: json
    register: page_contents
    until: page_contents.json.{{ foo }}[0].status == "deployed"
    retries: 30
    delay: 5

标签: ansibleansible-role

解决方案


我将 ansible 和 python 版本都更新到了最新版本,现在它工作正常。


推荐阅读