我正在尝试创建用于安装Tableau Server的剧本。但是有一部分需要响应。
这是我的代码:
- name: Apply Changes
expect:
command: /opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible
responses:
'This operation will perform a server restart. Are you sure you wish to continue?(y/n):': 'y'
timeout: 600
echo: yes
tags:
- start
但是我有一个错误
atal: [tableau3.server.com]: FAILED! => {
"changed": true,
"cmd": "/opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible",
"delta": "0:10:00.223831",
"end": "2019-05-05 21:16:46.914799",
"invocation": {
"module_args": {
"chdir": null,
"command": "/opt/tableau/tableau_server/packages/customer-bin.10500.19.0313.1245/tsm pending-changes apply -u ansible -p ansible",
"creates": null,
"echo": true,
"removes": null,
"responses": {
"This operation will perform a server restart. Are you sure you wish to continue?(y/n):": "y"
},
"timeout": 600
}
},
"msg": "non-zero return code",
"rc": 129,
"start": "2019-05-05 21:06:46.690968",
"stdout": "This operation will perform a server restart. Are you sure you wish to continue?\r\n(y/n): ",
"stdout_lines": [
"This operation will perform a server restart. Are you sure you wish to continue?",
"(y/n): "
]
}
答案 0 :(得分:2)
命令以2行响应
stdout_lines": [
"This operation will perform a server restart. Are you sure you wish to continue?",
"(y/n): "
,但响应中的项目只需要1行。
responses:
'This operation will perform a server restart. Are you sure you wish to continue?(y/n):': 'y'
因此,响应中没有任何项目适合并且模块失败。
响应为字符串/正则表达式。试试
responses:
y/n: 'y'
Notes说:
Expect模块是为简单方案设计的。对于更复杂的需求,请考虑将期望代码与shell或脚本模块一起使用。 (一个示例是外壳模块文档的一部分)