为什么我的自定义Ansible模块失败? [英] Why does my custom Ansible module fail?
本文介绍了为什么我的自定义Ansible模块失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习ansible,所以我写了我能想到的最简单的剧本和模块,但失败了.
I am learning ansible so I wrote the most simple playbook and module I could think of, and it failed.
我的剧本
---
- hosts: demo
tasks:
- name: install demo
action: install
我的模块
echo "changed=True msg=OK"
以下内容似乎不错:
- bash脚本模式为755
- 剧本已正确链接到模块
这是输出:
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?
推荐答案
模块的输出尝试一下:
echo "{\"changed\": false, \"msg\" : \"ok\"}"
从文档:
您也不应该在模块中执行此操作:
You should also never do this in a module:
print "some status message"
因为输出应该是有效的JSON.
Because the output is supposed to be valid JSON.
和:
如果模块返回stderr或以其他方式无法生成有效的JSON,则实际输出仍将显示在Ansible中,但命令将不会成功.
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.
这篇关于为什么我的自定义Ansible模块失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文