gpt4 book ai didi

ansible - 调试 Ansible 模块

转载 作者:行者123 更新时间:2023-12-03 23:21:26 25 4
gpt4 key购买 nike

我试图写一个 Ansible 模块。我的模块有问题。当我从剧本运行它时,我得到以下不可读的输出:

$ ansible-playbook lacp.yml 

PLAY [xxxxxxxx] ****************************************************************

TASK [Test that my module works] ***********************************************
fatal: [xxxxxxxx]: FAILED! => {"changed": false, "failed": true, "module_stderr": "couldn't set locale correctly\ncouldn't set locale correctly\ncouldn't set locale correctly\nTraceback (most recent call last):\n File \"/tmp/ansible_vHkWq8/ansible_module_lacp.py\", line 27, in <module>\n main()\n File \"/tmp/ansible_vHkWq8/ansible_module_lacp.py\", line 14, in main\n m = re.match('^key: ([0-9]+) ', dladm.readline())\nAttributeError: 'Popen' object has no attribute 'readline'\ndladm: insufficient privileges\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file 'lacp.retry'. [Errno 2] No such file or directory: ''


PLAY RECAP *********************************************************************
xxxxxxxx : ok=0 changed=0 unreachable=0 failed=1

如何使用 JSON 停止 Ansible 引用错误消息?还是有其他方法可以调试 Ansible 模块?

最佳答案

How to stop Ansible quoting error messages with JSON?



您可以使用 human_log.py插件强制 Ansible 在其输出中解释和打印换行符。

你把文件放到 /path/to/callback_plugins/目录并将以下内容添加到 ansible.cfg :
[defaults]
callback_plugins = /path/to/callback_plugins/

详细说明在 Human-Readable Ansible Playbook Log Output Using Callback Plugin博客文章。

关于ansible - 调试 Ansible 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39453586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com