【发布时间】:2020-05-31 13:19:35
【问题描述】:
请告知如何使用 python 交互脚本作为自定义模块。
我的 python 脚本有时会出现如下提示。
[ansible@localhost ~]$ python test.py
No errors found.
do you want to proceed [y/n]
[ansible@localhost ~]$
sometimes:
[ansible@localhost ~]$ python test.py
3 Errors found.
Cant proceed with script.
[ansible@localhost ~]$
输出结果和交互式输出可能会因条件而异,写在我的脚本中。
我想了解如何在ansible的自定义模块下使用这个脚本,并处理交互式提示响应..
我读到expect 模块可以帮助 ansible 提供响应,但在我的脚本中,响应不能始终相同。
例如,我尝试过期望模块,但由于我的 python 脚本结果不同,它失败了,它根据条件有 4-6 种响应。
"invocation": {
"module_args": {
"chdir": null,
"command": "/usr/bin/python3 test3.py",
"creates": null,
"echo": true,
"removes": null,
"responses": {
"do you want to proceed [y/n]": "y"
},
"timeout": 30
上面失败的输出是ansible期望上面提到的响应,但我的实际python脚本结果不同。
请指教。
谢谢。
【问题讨论】: