I think for MongoDB you need to add an extra repo in your system. It will not come with your CentOS DVD. So first create one repo file and copy the lines in a file as shown below.
After you saved this file in your Ansible node. Now you are ready to setup MongoDB. Create one playbook and write down the below code on that playbook.
- hosts: "Replace IP"
- name: Copy file with owner and permissions
src: /mongo.repo(repo file name that you have to create as shown above)
- name: Install mongodb-org package
- name: Start the service
Now run the playbook with the help of the below command.
$ ansible-playbook demo.yml