I am using uri
module of Ansible 2.0
.
I have code like this to make POST on a api.
- 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
I have 2 target servers in different inventories. This works againts server A. On server B is fails with error:
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'"}
If I do the POST manually with curl
both server A and B give same response.
Servers A and B have identical configuration.
If I run the play book with full verbosity I see only these lines before the error for the task in question:
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'"'"'"'"'"'"'"'"''"'"''
I can't figure out why this test fails for Ansible and why it happens only for the other server.