Simply run vagrant up
and the 3 mongo instances will be deployed and register in replica set
Last active
February 21, 2019 11:11
-
-
Save jmlrt/920d6589b1b86e4952c295bdfde79916 to your computer and use it in GitHub Desktop.
MongoDB RS provisioning with Vagrant & Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- src: https://github.com/UnderGreen/ansible-role-mongodb | |
scm: git | |
name: mongodb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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