Your mongodb role should look something like this:
- name: MongoDB - Import public key
apt_key:
keyserver: hkp://keyserver.ubuntu.com:80
id: EA312927
- name: MongoDB - Add repository
apt_repository:
filename: '/etc/apt/sources.list.d/mongodb-org-3.2.list'
repo: 'deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse'
state: present
update_cache: yes
- name: MongoDB - Install MongoDB
apt:
name: mongodb-org
state: present
update_cache: yes
- name: MongoDB - Running state
service:
name: mongod
state: started
Hope this helps!!
To know more about Mongodb, go for Mongodb training online without fail.
Thanks!