title: Restart MongoDB with Ansible, after EC2 reboots
body: <p>I'm using <a href="http://ansible.cc/" rel="nofollow">Ansible</a> to configure and deploy an EC2 instance, which is running MongoDB.</p>
  
  <p>I'm wondering now how can I configure MongoDB to be restarted automatically, after the EC2 instance is being rebooted. Or do I simply have to re-run the Ansible Playbook?</p>
  
  <p>This is my current <strong>Ansible Playbook</strong>:</p>
  
  <pre><code>- 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
  </code></pre>