Ansible Deployment of MongoDB Shard via Docker

Hosts Setup

  1. Create 2 host machines (vm's) using ubuntu live server 20.04
  2. Assign one to be the Ansible Control Host and the other to be the Managed Host
  3. Assign static IP's to both, make sure they're on the same network.

demo control node: user=sammy, pwd=password, ip=192.168.1.80

demo managed node: user=ansible, pwd=ansible, ip=192.168.1.81

  1. Initially both hosts only need a bare minimum install, basic Ubuntu + OpenSSH, no other apps.
  2. Log into the Control Node and do the following steps:
  3. Install ansible (see hw4 docs)
  4. establish a password based ssh connection from the control host to the managed host
  5. confirm user has sudoer (i.e. run '$ sudo -i')
  6. log out back to control node

Passwordless SSH connection

  1. create SSH key pairs for Control Host
 $ ssh-keygen
  1. push the public SSH key of the control node to the managed node (ssh)
 $ ssh-copy-id -i ansible@192.168.1.81 (provide passwords when requested)
  1. attempt to ssh connect without password
  2. install ansible on control node
  3. edt '$ /etc/ansible/hosts' file and add the following line
 [shards]
 192.168.1.81
  1. test ansible ping to managed host
 $ ansible shards -m ping -u ansible

Ansible Playbook Execution

  1. import the .zip file for hw4 and extract it in some folder
  2. from the extracted folder run the playbook with the following arguments
 $ ansible-playbook playbook.yml -l shards -u ansible -kK~
  1. when playbook has run, ssh into managed host
  2. May have to run playbook second time

Validation

  1. from managed host, check docker containers, should be 1 primary and 2 secondary
  $ sudo docker ps -a
  1. Done. If you don't see 1 primary and 2 secondary, re run the playbook once more and check back.