Python

Ansible 期望沒有發送響應

  • November 13, 2018

我是 ansible 的新手,並通過編寫用於安裝石墨的 ansible 劇本來嘗試它,作為其中的一部分,我有graphite-manage syncdb我想自動化的命令。

我寫了這個任務來自動回答提示,但由於某種原因它卡住並在超時時中斷。"msg": "command exceeded timeout"似乎它沒有發送我對提示答案的回复。我雖然可能是我使用的格式,我檢查了 ansible docs 上的範例,但它真的很簡單,沒有額外的資訊。

這是我的範例,請看一下:

---
   - 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:': 'test@test.com'
           '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): "]}

非常感謝你的幫助。

map 中的鍵response是正則表達式,因此?(...)被視為正則表達式控製字元,導致不匹配。

如果你真的想傳遞整個字元串,你應該使用:

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

但鑑於任何其他提示中沒有更多create on now文本,您可以使用:

responses:
 'create one now': 'yes'

引用自:https://serverfault.com/questions/939671