0
我使用Ansible來配置Vagrant虛擬機,它在vagrant up
上啓動mongoDB並創建一個數據庫並準備收集數據。另一個進程將數據寫入mongoDB集合。以下是劇本的一個片段:如何使用Ansible手冊在mongoDB中創建一個集合?
- hosts: all
user: vagrant
sudo: True
tasks:
- name: install packages
action: apt update_cache=yes pkg={{item}} state=installed
with_items:
- mongodb
- service: name=mongodb state=started
- shell: mongo mydb --eval "db.createCollection('mycollection')"
劇本安裝並啓動mongoDB服務。但是,它不創建數據庫/集合。 「- shell: mongo ...
」行有問題。它返回:
TASK: [shell mongo mydb --eval "db.createCollection('mycollection')"] ****
failed: [default] => {"changed": true, "cmd": "mongo mydb --eval\"db.createCollection('mycollection')\" ", "delta": "0:00:00.084196", "end": "2014-08-29 04:48:40.333460", "rc": 255, "start": "2014-08-29 04:48:40.249264"}
stderr: exception: connect failed
stdout: MongoDB shell version: 2.0.4
connecting to: mydb
Fri Aug 29 04:48:40 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
你能看到我做錯了嗎?
謝謝@tmruss。它以Ansible使用的相同用戶身份登錄時可以在shell中工作。它從劇本中不起作用。我不確定如何檢查虛擬機上的日誌,因爲它由於錯誤而未配置。 – 2014-08-29 05:32:37
@AlexWoolford也許我誤解了 - 如果你能從shell中測試它,你應該能夠訪問mongo日誌? – tmruss 2014-08-29 05:38:33
其他一些建議: - 確保你在mongo conf文件中有bind_ip = 127.0.0.1(放在那裏由你或者ansible/provisioners提供) - 有些人有幸運走了一個鎖文件,但我懷疑是你的情況下的問題,因爲它是一個流浪者vm: http://stackoverflow.com/questions/5726032/ – tmruss 2014-08-29 05:47:49