[root@localhost ~]# cat deploy_mongo.yaml --- - hosts: webservers become: yes become_method: sudo vars: mongodb_datadir_prefix: /data mongod_port: 25000 tasks: - name: create the mongodb user user: name=mongodb comment="MongoDB" - name: create the data directory for metadata file: path={{ mongodb_datadir_prefix }} owner=mongodb group=mongodb state=directory - name: install the mongodb command: yum install mongodb-org -y - name: create data directory for mongodb file: path: "{{ mongodb_datadir_prefix }}/mongo-{{ ansible_hostname }}" owner: mongodb group: mongodb state: directory - name: create log directory for mongodb file: path=/var/log/mongodb owner=mongodb group=mongodb state=directory - name: create the mongodb configuration file template: src=/root/mongodb.conf.j2 dest=/etc/mongod.conf - name: start mongodb command: systemctl start mongod.service