为什么我的自定义 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?
推荐答案
模块的输出 必须是 JSON.
试试这个:
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屋!
查看全文