kramer65 kramer65 - 1 year ago 387
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:// --recv EA312927
echo "deb 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
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 Source

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

# Install mongodb 
- name: Add mongo ppa key
  sudo: yes
  apt_key: >
- name: Add mongo sources list
  sudo: yes
  lineinfile: >
    line="deb trusty/mongodb-org/3.2 multiverse"
- name: Install mongo
  sudo: yes
  apt: name=mongodb-org state=latest update_cache=yes
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download