kramer65 kramer65 - 6 months ago 64
Linux Question

How to install MongoDB with Ansible?

I'm a beginner with Ansible and I'm now trying to install MongoDB on an Ubuntu 14.04 host. According to the MongoDB installation instructions the manual process is as follows:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org


I guess I can run this using the Ansible shell module, but since line 2 of the 4 lines about would constantly add new lines to the
mongodb-org-3.2.list
file I guess that is not the correct way.

Does anybody know what the logical way of doing this with Ansible is? All tips are welcome!

Answer

create your mongo-ansible.yml file and use this:

# Install mongodb 
---
- name: Add mongo ppa key
  sudo: yes
  apt_key: >
    keyserver=hkp://keyserver.ubuntu.com:80
    id=7F0CEB10
    state=present
- name: Add mongo sources list
  sudo: yes
  lineinfile: >
    line="deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse"
    dest=/etc/apt/sources.list.d/mongodb.list
    state=present
    create=yes
- name: Install mongo
  sudo: yes
  apt: name=mongodb-org state=latest update_cache=yes
Comments