Skip to content

Instantly share code, notes, and snippets.

@jmlrt
Last active February 21, 2019 11:11
Show Gist options
  • Save jmlrt/920d6589b1b86e4952c295bdfde79916 to your computer and use it in GitHub Desktop.
Save jmlrt/920d6589b1b86e4952c295bdfde79916 to your computer and use it in GitHub Desktop.
MongoDB RS provisioning with Vagrant & Ansible

MONGODB RS CONFIGURATION WITH SECURITY ENABLED

Simply run vagrant up and the 3 mongo instances will be deployed and register in replica set

---
- hosts: all
gather_facts: yes
become: yes
vars:
mongodb_net_bindip: 0.0.0.0
mongodb_security_authorization: "disabled"
mongodb_storage_dbpath: "/var/lib/mongo"
mongodb_storage_dirperdb: true
mongodb_storage_smallfiles: true
roles:
- mongodb
---
- src: https://github.com/UnderGreen/ansible-role-mongodb
scm: git
name: mongodb
Vagrant.configure("2") do |config|
(1..3).each do |i|
config.vm.define "mongo-rs0-#{i}" do |mongo|
mongo.vm.box = "centos/7"
mongo.vm.network "private_network", ip: "192.168.50.3#{i}"
mongo.vm.hostname = "mongo-rs0-#{i}"
end
end
config.vm.provision :shell, inline: "sudo yum -y install git"
config.vm.provision "ansible_local" do |ansible|
ansible.playbook = "deploy.yml"
ansible.galaxy_role_file = "requirements.yml"
ansible.groups = {
"mongo_master" => ["mongo-rs0-1"],
"mongo_replicas" => ["mongo-rs0-2", "mongo-rs0-3"],
"mongo:children" => ["mongo_master", "mongo_replicas"],
"mongo_master:vars" => { "mongodb_master" => "True"}
}
ansible.extra_vars = {
mongodb_replication_replset: "rs0",
mongodb_login_host: "192.168.50.31",
mongodb_replication_params: [
{
host_name: "{{ ansible_eth1.ipv4.address }}",
host_port: "{{ mongodb_net_port }}",
host_type: "replica"
}
],
mongodb_security_authorization: "enabled",
mongodb_set_parameters: {
"enableLocalhostAuthBypass": "true"
},
mongodb_user_admin_name: "siteUserAdmin",
mongodb_user_admin_password: "passw0rd",
mongodb_root_admin_name: "siteRootAdmin",
mongodb_root_admin_password: "passw0rd",
mongodb_users: [
{
name: "testUser",
password: "passw0rd",
roles: "readWrite",
database: "app_development"
}
]
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment