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 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.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.6.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!
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