我是 ansible 的新手,正在尝试通过编写 ansible 剧本来安装 graphite,作为它的一部分,我有一个graphite-manage syncdb
想要自动化的命令。
我编写此任务是为了自动响应提示,但由于某种原因,它卡住了,并在超时时中断。"msg": "command exceeded timeout"
而且它似乎没有将我的响应发送给提示的答案。我想也许是我使用的格式,我检查了 ansible 文档上的示例,但它真的很简单,不需要额外的信息。
这是我的示例,请看一下:
---
- hosts: localhost
tasks:
- name: graphite-web syncdb
expect:
command: sudo graphite-manage syncdb
responses:
'Would you like to create one now? (yes/no):': 'yes'
'Username (leave blank to use "root"):': '\n'
'Email address:': '[email protected]'
'Password:': '123123'
'Password (again):': '123123'
这是我收到的日志输出:
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "sudo graphite-manage syncdb", "delta": "0:00:30.107393", "end": "2018-11-12 15:39:01.897639", "msg": "command exceeded timeout", "rc": null, "start": "2018-11-12 15:38:31.790246", "stdout": "\u001b[36;1mOperations to perform:\u001b[0m\r\n\u001b[1m Synchronize unmigrated apps: \u001b[0maccount, cli, render, whitelist, metrics, url_shortener, dashboard, composer, events, browser\r\n\u001b[1m Apply all migrations: \u001b[0madmin, contenttypes, tagging, auth, sessions\r\n\u001b[36;1mSynchronizing apps without migrations:\u001b[0m\r\n Creating tables...\r\n Running deferred SQL...\r\n Installing custom SQL...\r\n\u001b[36;1mRunning migrations:\u001b[0m\r\n No migrations to apply.\r\n\r\nYou have installed Django's auth system, and don't have any superusers defined.\r\nWould you like to create one now? (yes/no): ", "stdout_lines": ["\u001b[36;1mOperations to perform:\u001b[0m", "\u001b[1m Synchronize unmigrated apps: \u001b[0maccount, cli, render, whitelist, metrics, url_shortener, dashboard, composer, events, browser", "\u001b[1m Apply all migrations: \u001b[0madmin, contenttypes, tagging, auth, sessions", "\u001b[36;1mSynchronizing apps without migrations:\u001b[0m", " Creating tables...", " Running deferred SQL...", " Installing custom SQL...", "\u001b[36;1mRunning migrations:\u001b[0m", " No migrations to apply.", "", "You have installed Django's auth system, and don't have any superusers defined.", "Would you like to create one now? (yes/no): "]}
非常感谢你的帮助。
答案1
映射中的键response
是正则表达式,因此?
和(...)
被视为正则表达式控制字符,导致不匹配。
如果您确实想传递整个字符串,您应该使用:
responses:
'Would you like to create one now\? \(yes/no\):': 'yes'
create on now
但鉴于其他提示中没有更多文本,您可以使用:
responses:
'create one now': 'yes'