问题
I am learning ansible so I wrote the most simple playbook and module I could think of, and it failed.
My playbook
---
- hosts: demo
tasks:
- name: install demo
action: install
My module
echo "changed=True msg=OK"
The following seems fine :
- bash script mode is 755
- playbook is linked to module correctly
This is the output:
FAILED! => {"changed": false, "failed": true, "module_stderr": "", "module_stdout": "changed=True msg=OK\r\n", "msg": "MODULE FAILURE", "parsed": false}
What am I doing wrong? How can I make this work?
回答1:
The output of a module must be JSON.
Try this:
echo "{\"changed\": false, \"msg\" : \"ok\"}"
From the docs:
You should also never do this in a module:
print "some status message"
Because the output is supposed to be valid JSON.
and:
If a module returns stderr or otherwise fails to produce valid JSON, the actual output will still be shown in Ansible, but the command will not succeed.
来源:https://stackoverflow.com/questions/34960794/why-does-my-custom-ansible-module-fail