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