大网数据广告活动
服务器运维问答

Ansible expect is not sending response

· 52CE 我爱测

I'm new to ansible and trying it by writing an ansible playbook for installing graphite, as a part of it I have the graphite-manage syncdb command which I would like to automate. I wrote this task to automatically answer to the p…

问题原文

原帖链接 · rivar_ · CC BY-SA 4.0

I'm new to ansible and trying it by writing an ansible playbook for installing graphite, as a part of it I have the graphite-manage syncdb command which I would like to automate.

I wrote this task to automatically answer to the promts but for some reason it get stuck and breaks on timeout. "msg": "command exceeded timeout" and it seems like it doesn't send my response to the promted answer. I though maybe its the format i used and I checked the samples on ansible docs but Its really simple without additional information.

Here is my sample, please take a look:

---
    - 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 omitted]'
            'Password:': '123123'
            'Password (again):': '123123'

This is the log output I recieved:

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): "]}

Thanks a lot for the assistance.

已采纳解答

原帖链接 · Konstantin Suvorov · CC BY-SA 4.0

Keys in response map are regular expressions, so ? and (...) are treated as regexp control characters resulting in no match.

If you really want to pass the whole string, you should use:

responses:
  'Would you like to create one now\? \(yes/no\):': 'yes'

But given there is no more create on now text in any other prompt, you can use:

responses:
  'create one now': 'yes'

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-11-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。