我使用Ansible來配置和部署正在運行MongoDB的EC2實例。在EC2重新啓動後用Ansible重啓MongoDB
我想知道現在如何配置MongoDB在EC2實例重新啓動後自動重啓。或者我只需要重新運行Ansible Playbook?
這是我目前Ansible劇本:
- hosts: staging_mongodb
user: ec2-user
sudo: yes
vars_files:
- vars/mongodb.yml
tasks:
- name: Check NTP
action: service name=ntpd state=started
- name: Copy MongoDB repo file
action: copy src=files/10gen.repo dest=/etc/yum.repos.d/10gen.repo
- name: Install MongoDB
action: yum pkg=mongo-10gen state=latest
- name: Install MongoDB server
action: yum pkg=mongo-10gen-server state=latest
- name: Template the MongoDB configuration file
action: template src=templates/mongod.conf.j2 dest=/etc/mongod.conf
- name: Prepare the database directory
action: file path=${db_path} state=directory recurse=yes owner=mongod group=mongod mode=0755
- name: Configure MongoDB
action: service name=mongod state=started enabled=yes
感謝您的回答! – Voles 2013-05-12 10:58:59
@Voles Btw,Ansible的回購有一些MongoDB的例子,考慮看看他們https://github.com/ansible/ansible-examples – Mxx 2013-05-12 19:03:57
這似乎是一個任務列表,所以'重新啓動mongodb'將無條件地開火時間。這些任務應該放在'tasks:'部分,並且放在'handlers:'部分。 – Nate 2013-05-14 10:16:41