我正在使用Ansible 2.0 uri模块。
我有这样的代码在api上进行POST。
- name: Example POST uri: url: http://example.com:8001/api method: POST status_code: 201 body_format: json body: key1: value key2: value2 register: response changed_when: response.status == 201
我有两个目标服务器在不同的库存。 这工作againts服务器答:服务器B上失败,错误:
fatal: [ip]: FAILED! => {"failed": true, "msg": "ERROR! The conditional check 'response.status == 201' failed. The error was: ERROR! error while evaluating conditional (response.status == 201): ERROR! 'dict object' has no attribute 'status'"}
如果我用curl手动执行POST,则服务器A和B将给出相同的响应。 服务器A和B具有相同的configuration。
如果我以完全冗长的方式运行游戏手册,则只会在所涉及的任务的错误之前看到以下这些行:
TASK [role : Example POST] *************************************** task path: /home/ansible/roles/role/tasks/example.yaml:15 <ip> ESTABLISH SSH CONNECTION FOR USER: ansible <ip> SSH: EXEC ssh -C -vvv -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansiblr -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r 10.100.105.22 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-cvyeydaqaapnnwuaukxffwmgvinzoxaq; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python'"'"'"'"'"'"'"'"''"'"''
我不明白为什么这个testing为Ansible失败,为什么它只发生在其他服务器上。
正如评论中所build议的,我使用debug模块来查看variables:
- debug: msg: '{{ response }}'
variables的内容是httplib2 >= 0.7 is not installed 。
所以我的环境丢失了uri模块需要的软件包。 根据文档,这只是在2.1以前的Ansible版本才需要。
安装软件包python-httplib2解决了这个问题。