Why does my custom Ansible module fail?

南楼画角 提交于 2020-01-05 11:01:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!