diff --git a/docs/server/source/appendices/run-with-ansible.md b/docs/server/source/appendices/run-with-ansible.md index 70e4b595..b3bcdfba 100644 --- a/docs/server/source/appendices/run-with-ansible.md +++ b/docs/server/source/appendices/run-with-ansible.md @@ -2,8 +2,8 @@ **NOT for Production Use** -You can use the following instructions to deploy a BigchainDB node for -dev/test using Ansible. Ansible will setup a BigchainDB node along with +You can use the following instructions to deploy a single or multi node +BigchainDB setup for dev/test using Ansible. Ansible will setup BigchainDB node(s) along with [Docker](https://www.docker.com/), [Docker Compose](https://docs.docker.com/compose/), [MongoDB](https://www.mongodb.com/), [BigchainDB Python driver](https://docs.bigchaindb.com/projects/py-driver/en/latest/). @@ -26,36 +26,113 @@ Navigate to `bigchaindb/pkg/scripts` and run the `bootstrap.sh` script to instal for your OS. The script also checks if the OS you are running is compatible with the supported versions. +**Note**: `bootstrap.sh` only supports Ubuntu >= 16.04, CentOS >= 7 and Fedora >=24. + ```text $ cd bigchaindb/pkg/scripts/ $ sudo ./bootstrap.sh ``` -### Local Setup | Ansible -You can safely run the `quickstart` playbook now and everything will be taken care of by `ansible` on your host. `quickstart` playbook only supports deployment on your dev/local host. To run the playbook please navigate to the ansible directory inside the BigchainDB repository and run the `quickstart` playbook. +### BigchainDB Setup Configuration(s) | Ansible +#### Local Setup | Ansible +You can run the Ansible playbook `bdb-deploy.yml` on your local dev machine and set up the BigchainDB node where +BigchainDB can be run as a process or inside a Docker container(s) depending on your configuratin. +Before, running the playbook locally, you need to update the `hosts` and `bdb-config.yml` configuration, which will notify Ansible that we need to run the play locally. + +##### Update Hosts | Local +Navigate to `bigchaindb/pkg/configuration/hosts` inside the BigchainDB repository. ```text -$ cd bigchaindb/pkg/ansible/ - -# All the services will be deployed as processes -$ sudo ansible-playbook quickstart.yml -c local - -OR - -# To deploy all services inside docker containers -$ sudo ansible-playbook quickstart.yml --extra-vars "with_docker=true" -c local +$ cd bigchaindb/pkg/configuration/hosts ``` -After successfull execution of the playbook, you can verify that BigchainDB docker/process is running. +Edit `all` configuration file: +```text +# Delete any existing configuration in this file and insert +localhost ansible_connection=local +``` +##### Update Configuration | Local +Navigate to `bigchaindb/pkg/configuration/vars` inside the BigchainDB repository. +```text +$ cd bigchaindb/pkg/configuration/vars/bdb-config.yml +``` -Verify BigchainDB process: +Edit `bdb-config.yml` configuration file as per your requirements, sample configuration file(s): +```text +--- +deploy_docker: false #[true, false] +docker_replset_size: 1 # Only needed if `deploy_docker` is true +bdb_hosts: + - name: "" +``` +**Note**: You can also orchestrate a multi-node BigchainDB cluster on a local dev host using Docker containers. +Here is a sample `bdb-config.yml` +```text +--- +deploy_docker: true #[true, false] +docker_replset_size: 3 +bdb_hosts: + - name: "" +``` + +#### Remote Setup | Ansible +You can also run the Ansible playbook `bdb-deploy.yml` on remote machine(s) and set up the BigchainDB node where +BigchainDB can be run as a process or inside a Docker container(s) depending on your configuration. + +Before, running the playbook on a remote host, you need to update the `hosts` and `bdb-config.yml` configuration, which will notify Ansible that we need to run the play on a remote host. + +##### Update Hosts | Remote +Navigate to `bigchaindb/pkg/configuration/hosts` inside the BigchainDB repository. +```text +$ cd bigchaindb/pkg/configuration/hosts +``` + +Edit `all` configuration file: +```text +# Delete any existing configuration in this file and insert + ansible_ssh_user= ansible_sudo_pass= +``` + +**Note 1**: You can multiple hosts to `all` configuration file. Root password is needed because ansible +will run some tasks that require root permissions. + +**Note 2**: You can also use other methods to get inside the remote machines instead of password based SSH. For other methods +please consult [Ansible Documentation](http://docs.ansible.com/ansible/latest/intro_getting_started.html). + +##### Update Configuration | Remote +Navigate to `bigchaindb/pkg/configuration/vars` inside the BigchainDB repository. +```text +$ cd bigchaindb/pkg/configuration/vars/bdb-config.yml +``` + +Edit `bdb-config.yml` configuration file as per your requirements, sample configuration file(s): +```text +--- +deploy_docker: false #[true, false] +docker_replset_size: 1 # Only needed if `deploy_docker` is true +bdb_hosts: + - name: "" +``` + +### BigchainDB Setup | Ansible +Now, You can safely run the `bdb-deploy.yml` playbook and everything will be taken care of by `Ansible`. To run the playbook please navigate to the `bigchaindb/pkg/configuration` directory inside the BigchainDB repository and run the `bdb-deploy.yml` playbook. + +```text +$ cd bigchaindb/pkg/configuration/ + +$ sudo ansible-playbook bdb-deploy.yml -i /bigchaindb/configuration/hosts/all +``` + +After successfull execution of the playbook, you can verify that BigchainDB docker(s)/process(es) is(are) running. + +Verify BigchainDB process(es): ```text $ ps -ef | grep bigchaindb ``` OR -Verify BigchainDB Docker: +Verify BigchainDB Docker(s): ```text $ docker ps | grep bigchaindb ``` diff --git a/docs/server/source/appendices/run-with-vagrant.md b/docs/server/source/appendices/run-with-vagrant.md index c396017a..e70dd715 100644 --- a/docs/server/source/appendices/run-with-vagrant.md +++ b/docs/server/source/appendices/run-with-vagrant.md @@ -2,10 +2,10 @@ **NOT for Production Use** -You can use the following instructions to deploy a BigchainDB node -for dev/test using Vagrant. Vagrant will setup a BigchainDB node with -all the dependencies along with MongoDB, BigchainDB Python driver. You -can also tweak the following configurations for the BigchainDB node. +You can use the following instructions to deploy a single or multi node +BigchainDB setup for dev/test using Vagrant. Vagrant will set up the BigchainDB node(s) +with all the dependencies along with MongoDB and BigchainDB Python driver. You +can also tweak the following configurations for the BigchainDB node(s). - Vagrant Box - Currently, we support the following boxes: - `ubuntu/xenial64 # >=16.04` @@ -19,10 +19,11 @@ can also tweak the following configurations for the BigchainDB node. - Network Type - Currently, only `private_network` is supported. - IP Address -- Setup type - - `quickstart` - Deploy node with Docker - Deploy all the services in Docker containers or as processes. +- Size of Replica Set(Number of cluster member) + - If you want to deploy the services inside Docker containers, you + can specify number of member(s) in the MongoDB/BigchainDB cluster. - Upstart Script - Vagrant Provider - Virtualbox @@ -38,64 +39,84 @@ $ git clone https://github.com/bigchaindb/bigchaindb.git ``` ## Configuration | Vagrant -Navigate to `bigchaindb/pkg/config/` inside the repository. +Navigate to `bigchaindb/pkg/config/` inside the BigchainDB repository. ```text $ cd bigchaindb/pkg/config/ ``` -Edit the `bdb-config.yaml` as per your requirements. Sample `bdb-config.yaml`: +Edit `bdb-config.yml` as per your requirements. Sample `bdb-config.yml`: ```text --- -- name: "bdb-node-01" - box: - name: "ubuntu/xenial64" - ram: "2048" - vcpus: "2" - setup_type: "quickstart" - deploy_docker: false - network: - ip: "10.20.30.40" - type: "private_network" - upstart: "/bigchaindb/scripts/bootstrap.sh" +deploy_docker: false #[true, false] +docker_replset_size: 1 +upstart: "/bigchaindb/scripts/bootstrap.sh" +bdb_hosts: + - name: "bdb-node-01" + box: + name: "ubuntu/xenial64" + ram: "2048" + vcpus: "2" + network: + ip: "10.20.30.40" + type: "private_network" ``` -**Note**: You can spawn multiple instances as well using `bdb-config.yaml`. Here is a sample `bdb-config.yaml`: +**Note**: You can spawn multiple instances to orchestrate a multi-node BigchainDB cluster. +Here is a sample `bdb-config.yml`: ```text --- -- name: "bdb-node-01" - box: - name: "ubuntu/xenial64" - ram: "2048" - vcpus: "2" - setup_type: "quickstart" - deploy_docker: false - network: - ip: "10.20.30.40" - type: "private_network" - upstart: "/bigchaindb/scripts/bootstrap.sh" -- name: "bdb-node-02" - box: - name: "ubuntu/xenial64" - ram: "4096" - vcpus: "3" - setup_type: "quickstart" - deploy_docker: false - network: - ip: "10.20.30.50" - type: "private_network" - upstart: "/bigchaindb/scripts/bootstrap.sh" +deploy_docker: false #[true, false] +docker_replset_size: 1 +upstart: "/bigchaindb/scripts/bootstrap.sh" +bdb_hosts: + - name: "bdb-node-01" + box: + name: "ubuntu/xenial64" + ram: "2048" + vcpus: "2" + network: + ip: "10.20.30.40" + type: "private_network" + - name: "bdb-node-02" + box: + name: "ubuntu/xenial64" + ram: "2048" + vcpus: "2" + network: + ip: "10.20.30.50" + type: "private_network" ``` +**Note**: You can also orchestrate a multi-node BigchainDB cluster on a single dev host using Docker containers. +Here is a sample `bdb-config.yml` +```text +--- +deploy_docker: true #[true, false] +docker_replset_size: 3 +upstart: "/bigchaindb/scripts/bootstrap.sh" +bdb_hosts: + - name: "bdb-node-01" + box: + name: "ubuntu/xenial64" + ram: "8192" + vcpus: "4" + network: + ip: "10.20.30.40" + type: "private_network" +``` +The above mentioned configuration will deploy a 3 node BigchainDB cluster with Docker containers +on your specified host. - -## Local Setup | Vagrant -To bring up the BigchainDB node, run the following command: +## BigchainDB Setup | Vagrant +To bring up the BigchainDB node(s), run the following command: ```text $ vagrant up ``` -*Note*: There are some vagrant plugins required for the installation, user will be prompted to install them if they are not present. Instructions to install the plugins can be extracted from the message. +**Note**: There are some vagrant plugins required for the installation, +user will be prompted to install them if they are not present. Instructions +to install the plugins can be extracted from the message. ```text $ vagrant plugin install @@ -108,16 +129,17 @@ $ vagrant ssh ``` ## Make your first transaction -Once you are inside the BigchainDB node, you can verify that BigchainDB docker/process is running. +Once you are inside the BigchainDB node, you can verify that BigchainDB +docker(s)/process(es) is(are) running. -Verify BigchainDB process: +Verify BigchainDB process(es): ```text $ ps -ef | grep bigchaindb ``` OR -Verify BigchainDB Docker: +Verify BigchainDB Docker(s): ```text $ docker ps | grep bigchaindb ``` diff --git a/pkg/Vagrantfile b/pkg/Vagrantfile index b8720016..8bfebe94 100644 --- a/pkg/Vagrantfile +++ b/pkg/Vagrantfile @@ -9,10 +9,12 @@ Vagrant.require_version '>= 1.6.0' VAGRANTFILE_API_VERSION = '2' # Configuration files -CONFIGURATION_FILE = 'config/bdb-config.yaml' +CONFIGURATION_FILE = 'configuration/vars/bdb-config.yml' +HOSTS_FILE = 'configuration/hosts/all' +HOST_VARS_PATH = 'configuration/host_vars' # Validate if all the required plugins are present -required_plugins = ["vagrant-cachier"] +required_plugins = ["vagrant-cachier", "vagrant-vbguest", "vagrant-hosts"] required_plugins.each do |plugin| if not Vagrant.has_plugin?(plugin) raise "Required vagrant plugin #{plugin} not found. Please run `vagrant plugin install #{plugin}`" @@ -21,10 +23,22 @@ end # Read configuration file(s) instances_config = YAML.load_file(File.join(File.dirname(__FILE__), CONFIGURATION_FILE)) - -#TODO: (muawiakh) Add support for Docker, AWS, Azure +hosts_config = File.open(HOSTS_FILE, 'w+') +# TODO: (muawiakh) Add support for Docker, AWS, Azure Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| - instances_config.each do |instance| + instances_config["bdb_hosts"].each do |instance| + # Workaround till canonical fixes https://bugs.launchpad.net/cloud-images/+bug/1569237 + # using -u ubuntu as remote user, conventionally vagrant boxes use `vagrant` user + if instance["box"]["name"] == "ubuntu/xenial64" + hosts_config.puts("#{instance["name"]} ansible_user=ubuntu") + if Vagrant.has_plugin?("vagrant-vbguest") + config.vbguest.auto_update = false + config.vbguest.no_install = true + config.vbguest.no_remote = true + end + else + hosts_config.puts("#{instance["name"]} ansible_user=vagrant") + end config.vm.define instance['name'] do |bdb| # Workaround until vagrant cachier plugin supports dnf if !(instance["box"]["name"].include? "fedora") @@ -40,14 +54,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| else raise "Invalid network type: Please specify one of the following: [private_network, public_network]" end + bdb.vm.provision :hosts, :sync_hosts => true bdb.vm.box = instance["box"]["name"] bdb.vm.synced_folder ".", "/bigchaindb" - bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instance["upstart"]}" - if instance["setup_type"] == "quickstart" - bdb.vm.provision :shell, inline: "PYTHONBUFFERED=1 ansible-playbook \ - /bigchaindb/ansible/quickstart.yml --extra-vars \"with_docker=#{instance["deploy_docker"]}\" -c local" - end - + File.open("#{HOST_VARS_PATH}/#{instance["name"]}", "w+") {|f| \ + f.write("ansible_ssh_private_key_file: /bigchaindb/.vagrant/machines/#{instance["name"]}/virtualbox/private_key") } + bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instances_config["upstart"]}" bdb.vm.provider 'vmware_fusion' do |vmwf, override| vmwf.vmx['memsize'] = instance["ram"] vmwf.vmx['numvcpus'] = instance['vcpus'] @@ -59,4 +71,32 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end end end + hosts_config.close + config.vm.define "config-node" do |bdb| + bdb.vm.box = "ubuntu/xenial64" + bdb.vm.hostname = "config-node" + bdb.vm.provision :hosts, :sync_hosts => true + bdb.vm.synced_folder ".", "/bigchaindb" + bdb.vm.network "private_network", ip: "192.168.100.200" + bdb.vm.provision :shell, inline: "cd /bigchaindb/scripts;/bin/bash #{instances_config["upstart"]}" + bdb.vm.provision :shell, inline: "PYTHONUNBUFFERED=1 ansible-playbook /bigchaindb/configuration/bdb-deploy.yml \ + -c /bigchaindb/configuration/hosts/all" + bdb.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] + vb.memory = 2048 + vb.cpus = 2 + end + bdb.vm.provider 'vmware_fusion' do |vmwf| + vmwf.vmx['memsize'] = 2048 + vmwf.vmx['numvcpus'] = 2 + end + if Vagrant.has_plugin?("vagrant-vbguest") + config.vbguest.auto_update = false + config.vbguest.no_install = true + config.vbguest.no_remote = true + end + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + end end diff --git a/pkg/ansible/quickstart.yml b/pkg/ansible/quickstart.yml deleted file mode 100644 index aa0f8c49..00000000 --- a/pkg/ansible/quickstart.yml +++ /dev/null @@ -1,10 +0,0 @@ -- hosts: localhost - remote_user: vagrant - vars: - with_docker: "{{ deploy_docker | default(false) }}" - roles: - - { role: docker, when: with_docker|bool } - - { role: docker-compose, when: with_docker|bool } - - mongodb - - bigchaindb - - bigchaindb-driver \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb/tasks/main.yml b/pkg/ansible/roles/bigchaindb/tasks/main.yml deleted file mode 100644 index 532c4ae6..00000000 --- a/pkg/ansible/roles/bigchaindb/tasks/main.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -- include: with_docker.yml - when: with_docker|bool - tags: [bigchaindb] - -- include: debian.yml - when: not with_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu") - -- include: centos.yml - when: not with_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux") - -- include: fedora.yml - when: not with_docker|bool and (distribution_name == "fedora") - -- include: common.yml - when: not with_docker|bool \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb/tasks/with_docker.yml b/pkg/ansible/roles/bigchaindb/tasks/with_docker.yml deleted file mode 100644 index bf832711..00000000 --- a/pkg/ansible/roles/bigchaindb/tasks/with_docker.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -- name: Configuring BigchainDB Docker - docker_container: - name: "{{ bigchaindb_docker_name }}" - image: "{{ bigchaindb_image_name }}" - volumes: "{{ bigchaindb_docker_volumes }}" - pull: false - env: - BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}" - BIGCHAINDB_DATABASE_HOST: "{{ bigchaindb_database_host }}" - entrypoint: "bigchaindb -y configure mongodb" - register: result - tags: [bigchaindb] - -- name: Start BigchainDB Docker - docker_container: - name: "{{ bigchaindb_docker_name }}" - image: "{{ bigchaindb_image_name }}" - published_ports: "{{ bigchaindb_docker_published_ports }}" - restart_policy: always - volumes: "{{ bigchaindb_docker_volumes }}" - state: started - pull: false - when: result|succeeded - tags: [bigchaindb] \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/tasks/common.yml b/pkg/ansible/roles/mongodb/tasks/common.yml deleted file mode 100644 index 41c6de1d..00000000 --- a/pkg/ansible/roles/mongodb/tasks/common.yml +++ /dev/null @@ -1,10 +0,0 @@ ---- -- name: MongoDB Process Check - shell: pgrep mongod | wc -l - register: command_result - tags: [mongodb] - -- name: Run MongoDB - shell: "mongod --replSet=bigchain-rs --logpath {{ mongodb_log_path }}/mongod.log &" - when: command_result.stdout| int != 1 - tags: [mongodb] \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/tasks/main.yml b/pkg/ansible/roles/mongodb/tasks/main.yml deleted file mode 100644 index 451b81b9..00000000 --- a/pkg/ansible/roles/mongodb/tasks/main.yml +++ /dev/null @@ -1,31 +0,0 @@ ---- -- name: Creating directories - file: - path: "{{ item }}" - state: directory - mode: 0700 - with_items: "{{ directories }}" - tags: [mongodb] - -- include: with_docker.yml - when: with_docker|bool - -- name: Verify logfiles exist | Debian - file: - path: "{{ mongodb_log_path }}/mongod.log" - state: touch - mode: 0755 - when: not with_docker|bool - tags: [mongodb] - -- include: debian.yml - when: not with_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu") - -- include: centos.yml - when: not with_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux") - -- include: fedora.yml - when: not with_docker|bool and (distribution_name == "fedora") - -- include: common.yml - when: not with_docker|bool \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/tasks/with_docker.yml b/pkg/ansible/roles/mongodb/tasks/with_docker.yml deleted file mode 100644 index ff3a24a5..00000000 --- a/pkg/ansible/roles/mongodb/tasks/with_docker.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -- name: Check Docker Service - systemd: - name: docker - enabled: yes - state: started - tags: [docker] - -- name: Running MongoDB Docker - docker_container: - name: "{{ mongodb_docker_name }}" - image: "{{ mongodb_docker_image }}" - detach: True - published_ports: "{{ mongodb_docker_published_ports }}" - restart_policy: always - volumes: "{{ mongodb_docker_volumes }}" - state: started - pull: false - entrypoint: /entrypoint.sh --replSet=bigchain-rs - tags: [mongodb] \ No newline at end of file diff --git a/pkg/config/bdb-config.yaml b/pkg/config/bdb-config.yaml deleted file mode 100644 index 86acac56..00000000 --- a/pkg/config/bdb-config.yaml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- name: "bdb-node-01" # Instance name - box: - name: "ubuntu/xenial64" # Box name - ram: "2048" - vcpus: "2" - setup_type: "quickstart" # Currently, only quickstart is supported. - deploy_docker: true # [true, false] - network: - ip: "10.20.30.50" - type: "private_network" - # Active network interface on host, Only required for public network e.g "en0: Wi-Fi (AirPort)" - bridge: "" - upstart: "/bigchaindb/scripts/bootstrap.sh" # Path to upstart script diff --git a/pkg/configuration/bdb-deploy.yml b/pkg/configuration/bdb-deploy.yml new file mode 100644 index 00000000..9bd93d98 --- /dev/null +++ b/pkg/configuration/bdb-deploy.yml @@ -0,0 +1,12 @@ +- import_playbook: pre_req.yml + +- hosts: all + vars_files: + - vars/bdb-config.yml + serial: 1 + roles: + - bigchaindb + - bigchaindb-driver + +- import_playbook: multi_node.yml + when: (bdb_hosts|length > 1) or docker_replset_size|int > 1 \ No newline at end of file diff --git a/pkg/configuration/group_vars/all b/pkg/configuration/group_vars/all new file mode 100644 index 00000000..f530443e --- /dev/null +++ b/pkg/configuration/group_vars/all @@ -0,0 +1,5 @@ +--- +ansible_connection: ssh +ansible_ssh_port: 22 +ansible_become: yes +ansible_ssh_common_args: '-o StrictHostKeyChecking=no' \ No newline at end of file diff --git a/pkg/configuration/host_vars/bdb-node-01 b/pkg/configuration/host_vars/bdb-node-01 new file mode 100644 index 00000000..e20d655a --- /dev/null +++ b/pkg/configuration/host_vars/bdb-node-01 @@ -0,0 +1,5 @@ +# Place holder file for users, running Ansible playbooks manually. Otherwise Vagrant +# populates this dynamically. + +# Only needed for logging into remote hosts and adding host specific variables e.g. +#ansible_ssh_private_key_file: "/path/to/private/key" \ No newline at end of file diff --git a/pkg/configuration/hosts/all b/pkg/configuration/hosts/all new file mode 100644 index 00000000..1f7800f2 --- /dev/null +++ b/pkg/configuration/hosts/all @@ -0,0 +1,8 @@ +# Place holder file for users, running Ansible playbooks manually. Otherwise Vagrant +# populates this dynamically. + +# For local host +#localhost ansible_connection=local + +# For remote host(s) +# ansible_ssh_user= ansible_sudo_pass= \ No newline at end of file diff --git a/pkg/configuration/multi_node.yml b/pkg/configuration/multi_node.yml new file mode 100644 index 00000000..aa293ad9 --- /dev/null +++ b/pkg/configuration/multi_node.yml @@ -0,0 +1,5 @@ +- hosts: all + vars_files: + - vars/bdb-config.yml + roles: + - key-exchange \ No newline at end of file diff --git a/pkg/configuration/pre_req.yml b/pkg/configuration/pre_req.yml new file mode 100644 index 00000000..b7e54581 --- /dev/null +++ b/pkg/configuration/pre_req.yml @@ -0,0 +1,8 @@ +- hosts: all + vars_files: + - vars/bdb-config.yml + serial: 1 + roles: + - { role: docker, when: deploy_docker|bool } + - { role: docker-compose, when: deploy_docker|bool } + - mongodb \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb-driver/defaults/main.yml b/pkg/configuration/roles/bigchaindb-driver/defaults/main.yml similarity index 62% rename from pkg/ansible/roles/bigchaindb-driver/defaults/main.yml rename to pkg/configuration/roles/bigchaindb-driver/defaults/main.yml index 63485cce..28c99323 100644 --- a/pkg/ansible/roles/bigchaindb-driver/defaults/main.yml +++ b/pkg/configuration/roles/bigchaindb-driver/defaults/main.yml @@ -23,4 +23,9 @@ dependencies_dnf: - python3-pip python_pip_upgrade: true -python_setuptools_upgrade: true \ No newline at end of file +python_setuptools_upgrade: true + +# Host configuration +distribution_name: "{{ ansible_distribution|lower }}" +distribution_codename: "{{ ansible_distribution_release|lower }}" +distribution_major: "{{ ansible_distribution_major_version }}" \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb-driver/tasks/centos.yml b/pkg/configuration/roles/bigchaindb-driver/tasks/centos.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb-driver/tasks/centos.yml rename to pkg/configuration/roles/bigchaindb-driver/tasks/centos.yml diff --git a/pkg/ansible/roles/bigchaindb-driver/tasks/common.yml b/pkg/configuration/roles/bigchaindb-driver/tasks/common.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb-driver/tasks/common.yml rename to pkg/configuration/roles/bigchaindb-driver/tasks/common.yml diff --git a/pkg/ansible/roles/bigchaindb-driver/tasks/debian.yml b/pkg/configuration/roles/bigchaindb-driver/tasks/debian.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb-driver/tasks/debian.yml rename to pkg/configuration/roles/bigchaindb-driver/tasks/debian.yml diff --git a/pkg/ansible/roles/bigchaindb-driver/tasks/fedora.yml b/pkg/configuration/roles/bigchaindb-driver/tasks/fedora.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb-driver/tasks/fedora.yml rename to pkg/configuration/roles/bigchaindb-driver/tasks/fedora.yml diff --git a/pkg/ansible/roles/bigchaindb-driver/tasks/main.yml b/pkg/configuration/roles/bigchaindb-driver/tasks/main.yml similarity index 65% rename from pkg/ansible/roles/bigchaindb-driver/tasks/main.yml rename to pkg/configuration/roles/bigchaindb-driver/tasks/main.yml index f743ff1c..f70ef304 100644 --- a/pkg/ansible/roles/bigchaindb-driver/tasks/main.yml +++ b/pkg/configuration/roles/bigchaindb-driver/tasks/main.yml @@ -1,12 +1,12 @@ --- -- include: debian.yml +- import_tasks: debian.yml when: distribution_name == "debian" or distribution_name == "ubuntu" -- include: centos.yml +- import_tasks: centos.yml when: distribution_name == "centos" or distribution_name == "red hat enterprise linux" -- include: fedora.yml +- import_tasks: fedora.yml when: distribution_name == "fedora" -- include: common.yml \ No newline at end of file +- import_tasks: common.yml \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb/defaults/main.yml b/pkg/configuration/roles/bigchaindb/defaults/main.yml similarity index 60% rename from pkg/ansible/roles/bigchaindb/defaults/main.yml rename to pkg/configuration/roles/bigchaindb/defaults/main.yml index 83058813..746cc8e6 100644 --- a/pkg/ansible/roles/bigchaindb/defaults/main.yml +++ b/pkg/configuration/roles/bigchaindb/defaults/main.yml @@ -27,21 +27,24 @@ dependencies_dnf: python_pip_upgrade: true python_setuptools_upgrade: true +# Host configuration +distribution_name: "{{ ansible_distribution|lower }}" +distribution_codename: "{{ ansible_distribution_release|lower }}" +distribution_major: "{{ ansible_distribution_major_version }}" + directories: - /data -backend_db: mongodb #[rethinkdb, mongodb] +backend_db: mongodb #[mongodb] +bigchaindb_config_path: /data/.bigchaindb bigchaindb_server_bind: "0.0.0.0:9984" -bigchaindb_database_host: "172.17.0.1" bigchaindb_log_file: "{{ ansible_env.HOME }}/bigchaindb.log" # Docker configuration -backend_db_image: "mongo:3.4.1" -backend_db_name: "mongodb" bigchaindb_image_name: "bigchaindb/bigchaindb" bigchaindb_docker_name: "bigchaindb" -bigchaindb_docker_published_ports: - - 59984:9984 -bigchaindb_docker_volumes: - - "{{ ansible_env.HOME }}/bigchaindb_docker:/data" +bigchaindb_default_port: 9984 +bigchandb_host_port: 59984 +bigchaindb_host_mount_dir: "{{ ansible_env.HOME }}/bigchaindb_docker" +bdb_docker_net_name: "bdb_network" diff --git a/pkg/ansible/roles/bigchaindb/tasks/centos.yml b/pkg/configuration/roles/bigchaindb/tasks/centos.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb/tasks/centos.yml rename to pkg/configuration/roles/bigchaindb/tasks/centos.yml diff --git a/pkg/ansible/roles/bigchaindb/tasks/common.yml b/pkg/configuration/roles/bigchaindb/tasks/common.yml similarity index 53% rename from pkg/ansible/roles/bigchaindb/tasks/common.yml rename to pkg/configuration/roles/bigchaindb/tasks/common.yml index c88882be..d29cc3ef 100644 --- a/pkg/ansible/roles/bigchaindb/tasks/common.yml +++ b/pkg/configuration/roles/bigchaindb/tasks/common.yml @@ -13,10 +13,18 @@ shell: "pip3 install bigchaindb" tags: [bigchaindb] +- name: Check if BigchainDB node is already configured + stat: + path: "{{ bigchaindb_config_path }}" + register: stat_result + - name: Configure BigchainDB shell: "bigchaindb -y configure {{ backend_db }}" environment: BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}" + BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path }}" + BIGCHAINDB_DATABASE_HOST: "{{ ansible_hostname }}" + when: stat_result.stat.exists == False tags: [bigchaindb] - name: MongoDB Process Check @@ -30,7 +38,22 @@ tags: [bigchaindb] - name: Start BigchainDB - become: yes shell: "bigchaindb start > {{ bigchaindb_log_file }} 2>&1 &" + environment: + BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path }}" when: mdb_pchk.stdout| int >= 1 and bdb_pchk.stdout| int == 0 - tags: [bigchaindb] \ No newline at end of file + async: 10 + poll: 0 + tags: [bigchaindb] + +- name: Get BigchainDB node public key + shell: "cat {{ bigchaindb_config_path }}" + register: bdb_node_config + tags: [bigchaindb] + +- name: Set Facts BigchainDB + set_fact: + pub_key="{{ ( bdb_node_config.stdout|from_json).keypair.public }}" + hostname="{{ ansible_hostname }}" + bdb_config="{{ bigchaindb_config_path }}" + tags: [bigchaindb] diff --git a/pkg/ansible/roles/bigchaindb/tasks/debian.yml b/pkg/configuration/roles/bigchaindb/tasks/debian.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb/tasks/debian.yml rename to pkg/configuration/roles/bigchaindb/tasks/debian.yml diff --git a/pkg/configuration/roles/bigchaindb/tasks/deploy_docker.yml b/pkg/configuration/roles/bigchaindb/tasks/deploy_docker.yml new file mode 100644 index 00000000..82ca060e --- /dev/null +++ b/pkg/configuration/roles/bigchaindb/tasks/deploy_docker.yml @@ -0,0 +1,51 @@ +--- +- name: Check if BigchainDB Dockers are already configured + stat: + path: "{{ bigchaindb_host_mount_dir }}{{ item|string }}/.bigchaindb" + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + register: stat_result + +- name: Configuring BigchainDB Docker + docker_container: + name: "{{ bigchaindb_docker_name }}{{ item }}" + hostname: "{{ bigchaindb_docker_name }}{{ item }}" + image: "{{ bigchaindb_image_name }}" + volumes: + - "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data" + env: + BIGCHAINDB_SERVER_BIND: "{{ bigchaindb_server_bind }}" + BIGCHAINDB_DATABASE_HOST: "{{ hostvars[ansible_hostname]['mongodb' + item|string] }}" + entrypoint: "bigchaindb -y configure mongodb" + networks: + - name: "{{ bdb_docker_net_name }}" + when: stat_result.results[item|int].stat.exists == False + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [bigchaindb] + +- name: Start BigchainDB Docker + docker_container: + name: "{{ bigchaindb_docker_name }}{{ item }}" + image: "{{ bigchaindb_image_name }}" + detach: true + published_ports: + - "{{ bigchandb_host_port|int + item|int }}:{{ bigchaindb_default_port }}" + restart_policy: always + volumes: + - "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data" + networks: + - name: "{{ bdb_docker_net_name }}" + state: started + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [bigchaindb] + +- name: Get BigchainDB node public key + shell: "cat {{ bigchaindb_host_mount_dir + item|string }}/.bigchaindb" + register: bdb_node_config + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [bigchaindb] + +- name: Set facts for BigchainDB containers + set_fact: + pub_key_{{ bigchaindb_docker_name }}{{ item }}="{{ (bdb_node_config.results[item|int].stdout|from_json).keypair.public }}" + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [mongodb] \ No newline at end of file diff --git a/pkg/ansible/roles/bigchaindb/tasks/fedora.yml b/pkg/configuration/roles/bigchaindb/tasks/fedora.yml similarity index 100% rename from pkg/ansible/roles/bigchaindb/tasks/fedora.yml rename to pkg/configuration/roles/bigchaindb/tasks/fedora.yml diff --git a/pkg/configuration/roles/bigchaindb/tasks/main.yml b/pkg/configuration/roles/bigchaindb/tasks/main.yml new file mode 100644 index 00000000..207bee93 --- /dev/null +++ b/pkg/configuration/roles/bigchaindb/tasks/main.yml @@ -0,0 +1,20 @@ +--- +- import_tasks: deploy_docker.yml + when: deploy_docker|bool + tags: [bigchaindb] + +- import_tasks: debian.yml + when: not deploy_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu") + tags: [bigchaindb] + +- import_tasks: centos.yml + when: not deploy_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux") + tags: [bigchaindb] + +- import_tasks: fedora.yml + when: not deploy_docker|bool and (distribution_name == "fedora") + tags: [bigchaindb] + +- import_tasks: common.yml + when: not deploy_docker|bool + tags: [bigchaindb] \ No newline at end of file diff --git a/pkg/ansible/roles/docker-compose/defaults/main.yml b/pkg/configuration/roles/docker-compose/defaults/main.yml similarity index 100% rename from pkg/ansible/roles/docker-compose/defaults/main.yml rename to pkg/configuration/roles/docker-compose/defaults/main.yml diff --git a/pkg/ansible/roles/docker-compose/tasks/main.yml b/pkg/configuration/roles/docker-compose/tasks/main.yml similarity index 100% rename from pkg/ansible/roles/docker-compose/tasks/main.yml rename to pkg/configuration/roles/docker-compose/tasks/main.yml diff --git a/pkg/ansible/roles/docker/defaults/main.yml b/pkg/configuration/roles/docker/defaults/main.yml similarity index 100% rename from pkg/ansible/roles/docker/defaults/main.yml rename to pkg/configuration/roles/docker/defaults/main.yml diff --git a/pkg/ansible/roles/docker/tasks/centos.yml b/pkg/configuration/roles/docker/tasks/centos.yml similarity index 100% rename from pkg/ansible/roles/docker/tasks/centos.yml rename to pkg/configuration/roles/docker/tasks/centos.yml diff --git a/pkg/ansible/roles/docker/tasks/debian.yml b/pkg/configuration/roles/docker/tasks/debian.yml similarity index 100% rename from pkg/ansible/roles/docker/tasks/debian.yml rename to pkg/configuration/roles/docker/tasks/debian.yml diff --git a/pkg/ansible/roles/docker/tasks/fedora.yml b/pkg/configuration/roles/docker/tasks/fedora.yml similarity index 100% rename from pkg/ansible/roles/docker/tasks/fedora.yml rename to pkg/configuration/roles/docker/tasks/fedora.yml diff --git a/pkg/ansible/roles/docker/tasks/main.yml b/pkg/configuration/roles/docker/tasks/main.yml similarity index 87% rename from pkg/ansible/roles/docker/tasks/main.yml rename to pkg/configuration/roles/docker/tasks/main.yml index 66d36489..5676e153 100644 --- a/pkg/ansible/roles/docker/tasks/main.yml +++ b/pkg/configuration/roles/docker/tasks/main.yml @@ -1,11 +1,11 @@ --- -- include: debian.yml +- import_tasks: debian.yml when: distribution_name == "debian" or distribution_name == "ubuntu" -- include: centos.yml +- import_tasks: centos.yml when: distribution_name == "centos" or distribution_name == "red hat enterprise linux" -- include: fedora.yml +- import_tasks: fedora.yml when: distribution_name == "fedora" - name: Create Docker group diff --git a/pkg/configuration/roles/key-exchange/defaults/main.yml b/pkg/configuration/roles/key-exchange/defaults/main.yml new file mode 100644 index 00000000..3bc2d64a --- /dev/null +++ b/pkg/configuration/roles/key-exchange/defaults/main.yml @@ -0,0 +1,13 @@ +keyring_script_host: /tmp/keyring.py +bigchaindb_log_file_host: "{{ ansible_env.HOME }}/bigchaindb.log" +bigchaindb_config_path_host: /data/.bigchaindb + +# Docker configuration +keyring_script_docker: "{{ ansible_env.HOME }}/config/keyring.py" +bigchaindb_config_path_docker: "{{ ansible_env.HOME }}/bigchaindb_docker" +bigchaindb_docker_name: bigchaindb +bigchaindb_default_port: 9984 +bigchandb_host_port: 59984 +bigchaindb_host_mount_dir: "{{ ansible_env.HOME }}/bigchaindb_docker" +bigchaindb_image_name: "bigchaindb/bigchaindb" +bdb_docker_net_name: "bdb_network" \ No newline at end of file diff --git a/pkg/configuration/roles/key-exchange/tasks/main.yml b/pkg/configuration/roles/key-exchange/tasks/main.yml new file mode 100644 index 00000000..031bf16b --- /dev/null +++ b/pkg/configuration/roles/key-exchange/tasks/main.yml @@ -0,0 +1,8 @@ +--- +- include_tasks: pub_key_exchange_host.yml + when: not deploy_docker|bool + tags: [bigchaindb] + +- include_tasks: pub_key_exchange_docker.yml + when: deploy_docker|bool + tags: [bigchaindb] \ No newline at end of file diff --git a/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_docker.yml b/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_docker.yml new file mode 100644 index 00000000..87772617 --- /dev/null +++ b/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_docker.yml @@ -0,0 +1,31 @@ +--- +- name: Creating files for key exchange + template: src=exchange_keyring_docker.j2 dest="{{ keyring_script_docker }}" + tags: [keyex] + +- name: Setting permissions + file: + path: "{{ keyring_script_docker }}" + mode: "0777" + tags: [keyex] + +- name: Update Keyring Configuration + shell: "python {{ keyring_script_docker }}" + tags: [keyex] + +- name: Restart BigchainDB Docker after keyring update + docker_container: + name: "{{ bigchaindb_docker_name }}{{ item }}" + image: "{{ bigchaindb_image_name }}" + detach: true + published_ports: + - "{{ bigchandb_host_port|int + item|int }}:{{ bigchaindb_default_port }}" + restart_policy: always + volumes: + - "{{ bigchaindb_host_mount_dir }}{{ item|string }}:/data" + state: started + restart: true + networks: + - name: "{{ bdb_docker_net_name }}" + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [bigchaindb] \ No newline at end of file diff --git a/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_host.yml b/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_host.yml new file mode 100644 index 00000000..f3d5c4d6 --- /dev/null +++ b/pkg/configuration/roles/key-exchange/tasks/pub_key_exchange_host.yml @@ -0,0 +1,28 @@ +--- +- name: Creating files for key exchange + template: src=exchange_keyring_host.j2 dest="{{ keyring_script_host }}" + tags: [keyex] + +- name: Setting permissions + file: + path: "{{ keyring_script_host }}" + mode: "0777" + tags: [keyex] + +- name: Update Keyring Configuration + shell: "python {{ keyring_script_host }}" + tags: [keyex] + +- name: Stop BigchainDB + shell: pkill bigchaindb + register: bdb_stop + tags: [keyex] + +- name: Start BigchainDB + shell: "bigchaindb start > {{ bigchaindb_log_file_host }} 2>&1 &" + environment: + BIGCHAINDB_CONFIG_PATH: "{{ bigchaindb_config_path_host }}" + async: 10 + poll: 0 + when: bdb_stop|succeeded + tags: [bigchaindb] \ No newline at end of file diff --git a/pkg/configuration/roles/key-exchange/templates/exchange_keyring_docker.j2 b/pkg/configuration/roles/key-exchange/templates/exchange_keyring_docker.j2 new file mode 100644 index 00000000..04c30716 --- /dev/null +++ b/pkg/configuration/roles/key-exchange/templates/exchange_keyring_docker.j2 @@ -0,0 +1,18 @@ +#!/usr/bin/python +import json +{% set keyring = {} %} +{% for docker in range(0, docker_replset_size|int, 1) %} + {{- keyring.update({'pub_key_' + bigchaindb_docker_name + docker|string: hostvars[ansible_hostname]['pub_key_' + bigchaindb_docker_name + docker|string]}) -}} +{%- endfor -%} +{% for docker in range(0, docker_replset_size|int, 1) %} +keyring = {{ keyring }} +keyring.pop('{{ 'pub_key_' + bigchaindb_docker_name + docker|string }}', None) +with open('{{ bigchaindb_config_path_docker + docker|string }}/.bigchaindb', 'r+') as f: + data = json.load(f) + del data['keyring'][:] + for key, value in keyring.iteritems(): + data['keyring'].append(value) + f.seek(0) + json.dump(data, f, indent=4) + f.truncate() +{% endfor %} \ No newline at end of file diff --git a/pkg/configuration/roles/key-exchange/templates/exchange_keyring_host.j2 b/pkg/configuration/roles/key-exchange/templates/exchange_keyring_host.j2 new file mode 100644 index 00000000..f02a208c --- /dev/null +++ b/pkg/configuration/roles/key-exchange/templates/exchange_keyring_host.j2 @@ -0,0 +1,21 @@ +{%- set keyring = [] -%} +{%- set bdb_config_path = {'path': ''} -%} +{%- for host in bdb_hosts -%} + {%- if host["name"] != ansible_hostname -%} + {{- keyring.append(hostvars[host["name"]]["pub_key"]) -}} + {%- else -%} + {%- if bdb_config_path.update({'path': hostvars[host["name"]]["bdb_config"]}) -%} + {%- endif -%} + {%- endif -%} +{%- endfor -%} +{%- if keyring|length != 0 -%} +#!/usr/bin/python +import json +with open('{{ bdb_config_path['path'] }}', 'r+') as f: + data = json.load(f) + del data['keyring'][:] + data['keyring'] = {{ keyring }} + f.seek(0) + json.dump(data, f, indent=4) + f.truncate() +{%- endif -%} \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/defaults/main.yml b/pkg/configuration/roles/mongodb/defaults/main.yml similarity index 70% rename from pkg/ansible/roles/mongodb/defaults/main.yml rename to pkg/configuration/roles/mongodb/defaults/main.yml index 950b4a18..1e4bfcf5 100644 --- a/pkg/ansible/roles/mongodb/defaults/main.yml +++ b/pkg/configuration/roles/mongodb/defaults/main.yml @@ -17,20 +17,27 @@ mongodb_dnf_base_url: "https://repo.mongodb.org/yum/{{ ansible_os_family|lower } mongodb_storage_path: /data/db/main mongodb_log_path: /var/log/mongodb mongodb_config_path: /data/configdb -se_linux: "TODO: (muawiakh)" directories: - "{{ mongodb_storage_path }}" - "{{ mongodb_log_path }}" - "{{ mongodb_config_path }}" +mongodb_conf_file: /etc/mongod.conf +mongodb_conf_files: [ + { src: "mongod.conf", dest: "{{ mongodb_conf_file }}"} +] +mongodb_port: 27017 +mongodb_admin_user: "adminUser" +mongodb_admin_password: "superstrongpassword" + +replica_set_name: bigchain-rs + +bdb_docker_net_name: "bdb_network" +bdb_docker_default_subnet: "172.18.0.0/16" +bdb_docker_default_gw: "172.18.0.1" + # Docker configuration -mongodb_default_port: 27017 -mongodb_docker_image: "mongo:3.4.4" +mongodb_docker_image: "mongo:3.4.9" mongodb_docker_name: "mongodb" -mongodb_docker_published_ports: - - 172.17.0.1:27017:27017 -mongodb_host_mount_dir_db: /tmp/mongodb_docker/db -mongodb_host_mount_dir_config: /tmp/mongodb_docker/configdb -mongodb_docker_volumes: - - "{{ mongodb_host_mount_dir_db }}:{{ mongodb_storage_path }}" - - "{{ mongodb_host_mount_dir_config }}:{{ mongodb_config_path }}" \ No newline at end of file +mongodb_host_mount_dir: "{{ ansible_env.HOME }}/mongodb_docker" +mongodb_host_config: "{{ ansible_env.HOME }}/config" \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/files/mongod.conf b/pkg/configuration/roles/mongodb/files/mongod.conf new file mode 100644 index 00000000..ed961801 --- /dev/null +++ b/pkg/configuration/roles/mongodb/files/mongod.conf @@ -0,0 +1,101 @@ +# mongod.conf + +# for documentation of all options, see: +# http://docs.mongodb.org/manual/reference/configuration-options/ + +# where to write logging data. +systemLog: + verbosity: 0 + # traceAllExceptions: true + timeStampFormat: iso8601-utc + component: + accessControl: + verbosity: 0 + command: + verbosity: 0 + control: + verbosity: 0 + ftdc: + verbosity: 0 + geo: + verbosity: 0 + index: + verbosity: 0 + network: + verbosity: 0 + query: + verbosity: 0 + replication: + verbosity: 0 + sharding: + verbosity: 0 + storage: + verbosity: 0 + journal: + verbosity: 0 + write: + verbosity: 0 + +processManagement: + fork: false + pidFilePath: /tmp/mongod.pid + +net: + port: 27017 + bindIp: 0.0.0.0 + maxIncomingConnections: 8192 + wireObjectCheck: false + unixDomainSocket: + enabled: false + pathPrefix: /tmp + filePermissions: 0700 + http: + enabled: false + compression: + compressors: snappy +# ssl: +# mode: requireSSL +# PEMKeyFile: MONGODB_KEY_FILE_PATH +# PEMKeyPassword: MONGODB_KEY_FILE_PASSWORD +# CAFile: MONGODB_CA_FILE_PATH +# CRLFile: MONGODB_CRL_FILE_PATH + +# allowConnectionsWithoutCertificates: false +# allowInvalidHostnames: false +# weakCertificateValidation: false +# allowInvalidCertificates: false + +#security: +# authorization: enabled +# clusterAuthMode: x509 + +#setParameter: +# enableLocalhostAuthBypass: true +# #notablescan: 1 +# logUserIds: 1 +# authenticationMechanisms: MONGODB-X509,SCRAM-SHA-1 + +storage: + dbPath: /data/db/main + indexBuildRetry: true + journal: + enabled: true + commitIntervalMs: 100 + directoryPerDB: true + engine: wiredTiger + wiredTiger: + engineConfig: + journalCompressor: snappy +# configString: cache_size=STORAGE_ENGINE_CACHE_SIZE + collectionConfig: + blockCompressor: snappy + indexConfig: + prefixCompression: true # TODO false may affect performance? + +operationProfiling: + mode: slowOp + slowOpThresholdMs: 100 + +replication: + replSetName: bigchain-rs + enableMajorityReadConcern: true diff --git a/pkg/ansible/roles/mongodb/tasks/centos.yml b/pkg/configuration/roles/mongodb/tasks/centos.yml similarity index 76% rename from pkg/ansible/roles/mongodb/tasks/centos.yml rename to pkg/configuration/roles/mongodb/tasks/centos.yml index e3340100..62e8faa0 100644 --- a/pkg/ansible/roles/mongodb/tasks/centos.yml +++ b/pkg/configuration/roles/mongodb/tasks/centos.yml @@ -15,4 +15,11 @@ name: "{{ mongodb_package }}" state: present update_cache: yes + tags: [mongodb] + +- name: Install pip | CentOS + yum: + name: python-pip + state: present + update_cache: yes tags: [mongodb] \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/common.yml b/pkg/configuration/roles/mongodb/tasks/common.yml new file mode 100644 index 00000000..40369191 --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/common.yml @@ -0,0 +1,25 @@ +--- +- name: MongoDB config files are copied + copy: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + with_items: "{{ mongodb_conf_files }}" + tags: [mongodb] + +- name: MongoDB Process Check + shell: pgrep mongod | wc -l + register: command_result + tags: [mongodb] + +- name: Install pymongo + pip: + name: pymongo + state: present + tags: [mongodb] + +- name: Run MongoDB + shell: "mongod --config {{ mongodb_conf_file }} 2>&1 &" + when: command_result.stdout| int != 1 + async: 5 + poll: 0 + tags: [mongodb] \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/tasks/debian.yml b/pkg/configuration/roles/mongodb/tasks/debian.yml similarity index 78% rename from pkg/ansible/roles/mongodb/tasks/debian.yml rename to pkg/configuration/roles/mongodb/tasks/debian.yml index c2b0349b..aac606fa 100644 --- a/pkg/ansible/roles/mongodb/tasks/debian.yml +++ b/pkg/configuration/roles/mongodb/tasks/debian.yml @@ -3,8 +3,6 @@ apt_key: keyserver: "{{ apt_keyserver }}" id: "{{ apt_key_fingerprint }}" - state: present - ignore_errors: true tags: [mongodb] - name: Add MongoDB repo and update cache | Debian @@ -16,6 +14,9 @@ - name: Install MongoDB | Debian apt: - name: "{{ mongodb_package }}" + name: "{{ item }}" state: present + with_items: + - "{{ mongodb_package }}" + - python-pip tags: [mongodb] \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/deploy_docker.yml b/pkg/configuration/roles/mongodb/tasks/deploy_docker.yml new file mode 100644 index 00000000..52ec3fde --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/deploy_docker.yml @@ -0,0 +1,48 @@ +--- +- name: Check Docker Service + systemd: + name: docker + enabled: yes + state: started + tags: [mongodb] + +- name: Creating BDB Docker network + docker_network: + name: "{{ bdb_docker_net_name }}" + ipam_options: + subnet: "{{ bdb_docker_default_subnet }}" + driver_options: + com.docker.network.bridge.enable_icc": "true" + com.docker.network.bridge.enable_ip_masquerade": "true" + com.docker.network.bridge.host_binding_ipv4": "0.0.0.0" + com.docker.network.driver.mtu: "1500" + state: present + tags: [mongodb] + +- name: Running MongoDB Docker + docker_container: + name: "{{ mongodb_docker_name }}{{ item }}" + hostname: "{{ mongodb_docker_name }}{{ item }}" + image: "{{ mongodb_docker_image }}" + detach: true + published_ports: + - "{{ bdb_docker_default_gw }}:{{ (mongodb_port|int + item|int)|string }}:{{ mongodb_port }}" + restart_policy: always + volumes: + - "{{ mongodb_host_mount_dir }}{{ item|string }}/db:{{ mongodb_storage_path }}" + - "{{ mongodb_host_mount_dir }}{{ item|string }}/configdb:{{ mongodb_config_path }}" + - "{{ mongodb_host_config }}:/bdb_config" + state: started + keep_volumes: true + entrypoint: /entrypoint.sh --replSet=bigchain-rs + networks: + - name: "{{ bdb_docker_net_name }}" + register: mongo_container_info + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [mongodb] + +- name: Set facts for MongoDB containers + set_fact: + mongodb{{ item }}={{ mongo_container_info.results[item|int].ansible_facts.docker_container.NetworkSettings.IPAddress }} + with_sequence: start=0 end="{{ docker_replset_size|int - 1 }}" stride=1 + tags: [mongodb] \ No newline at end of file diff --git a/pkg/ansible/roles/mongodb/tasks/fedora.yml b/pkg/configuration/roles/mongodb/tasks/fedora.yml similarity index 82% rename from pkg/ansible/roles/mongodb/tasks/fedora.yml rename to pkg/configuration/roles/mongodb/tasks/fedora.yml index fb83357f..c2f61110 100644 --- a/pkg/ansible/roles/mongodb/tasks/fedora.yml +++ b/pkg/configuration/roles/mongodb/tasks/fedora.yml @@ -12,6 +12,8 @@ - name: Install MongoDB | Fedora dnf: - name: "{{ mongodb_package }}" + name: "{{ item }}" state: present + with_items: + - "{{ mongodb_package }}" tags: [mongodb] \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/initiate_repl_set.yml b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set.yml new file mode 100644 index 00000000..2fed72d7 --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set.yml @@ -0,0 +1,6 @@ +--- +- import_tasks: initiate_repl_set_host.yml + when: (ansible_hostname == bdb_hosts[bdb_hosts|length-1]['name']) and not deploy_docker|bool + +- import_tasks: initiate_repl_set_docker.yml + when: deploy_docker|bool \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_docker.yml b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_docker.yml new file mode 100644 index 00000000..af5b89ca --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_docker.yml @@ -0,0 +1,13 @@ +--- +- name: Creating files to initialize MongoDB Replica Set | Docker + template: src=replSet_init_docker.j2 dest="{{ mongodb_host_config }}/replSet_init.js" + tags: [mongodb] + +- name: Initializing Replica Set and Adding AdminUser | Docker + run_once: true + shell: + cmd: + "docker exec {{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }} bash -l -c + '/usr/bin/mongo --host {{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }} + --port {{ mongodb_port }} < /bdb_config/replSet_init.js'" + tags: [mongodb] \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_host.yml b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_host.yml new file mode 100644 index 00000000..8d398bcb --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/initiate_repl_set_host.yml @@ -0,0 +1,20 @@ +--- +- name: Creating files to initialize MongoDB Replica Set + template: src=replSet_init_host.j2 dest=/tmp/replSet_init.js + tags: [mongodb] + +- name: Initializing Replica Set + shell: "/usr/bin/mongo --host {{ ansible_hostname }} --port {{ mongodb_port }} < /tmp/replSet_init.js" + tags: [mongodb] + +- name: Adding AdminUser to MongoDB + run_once: true + mongodb_user: + database: admin + login_host: "{{ ansible_hostname }}" + login_port: "{{ mongodb_port }}" + name: "{{ mongodb_admin_user }}" + password: "{{ mongodb_admin_password }}" + roles: readWriteAnyDatabase,clusterManager + state: present + tags: [mongodb] \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/tasks/main.yml b/pkg/configuration/roles/mongodb/tasks/main.yml new file mode 100644 index 00000000..6576d4c2 --- /dev/null +++ b/pkg/configuration/roles/mongodb/tasks/main.yml @@ -0,0 +1,31 @@ +--- +- name: Creating directories + file: + path: "{{ item }}" + state: directory + mode: 0700 + with_items: "{{ directories }}" + when: not deploy_docker|bool + tags: [mongodb] + +- import_tasks: deploy_docker.yml + when: deploy_docker|bool + tags: [mongodb] + +- import_tasks: debian.yml + when: not deploy_docker|bool and (distribution_name == "debian" or distribution_name == "ubuntu") + tags: [mongodb] + +- import_tasks: centos.yml + when: not deploy_docker|bool and (distribution_name == "centos" or distribution_name == "red hat enterprise linux") + tags: [mongodb] + +- import_tasks: fedora.yml + when: not deploy_docker|bool and (distribution_name == "fedora") + tags: [mongodb] + +- import_tasks: common.yml + when: not deploy_docker|bool + tags: [mongodb] + +- import_tasks: initiate_repl_set.yml \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/templates/replSet_init_docker.j2 b/pkg/configuration/roles/mongodb/templates/replSet_init_docker.j2 new file mode 100644 index 00000000..a0121b19 --- /dev/null +++ b/pkg/configuration/roles/mongodb/templates/replSet_init_docker.j2 @@ -0,0 +1,30 @@ +rs.initiate({ + "_id": "{{ replica_set_name }}", + "members": [ + { + "_id": 0, + "host": "{{ mongodb_docker_name }}{{ docker_replset_size|int - 1 }}:{{ mongodb_port }}" + } + ] +}); +sleep(5000); +{% for docker in range(0, docker_replset_size|int, 1) %} +{%- if docker != (docker_replset_size|int - 1) -%} +rs.add("{{ mongodb_docker_name }}{{ docker }}:{{ mongodb_port }}"); +{% endif %} +{%- endfor -%} +use admin; +db.createUser(db.createUser({ + "user": "{{ mongodb_admin_user }}", + "pwd": "{{ mongodb_admin_password }}", + "roles": [ + { + "role": "userAdminAnyDatabase", + "db": "admin" + }, + { + "role": "clusterManager", + "db": "admin" + } + ] +}); \ No newline at end of file diff --git a/pkg/configuration/roles/mongodb/templates/replSet_init_host.j2 b/pkg/configuration/roles/mongodb/templates/replSet_init_host.j2 new file mode 100644 index 00000000..42bca2a3 --- /dev/null +++ b/pkg/configuration/roles/mongodb/templates/replSet_init_host.j2 @@ -0,0 +1,7 @@ +rs.initiate( { _id : "{{ replica_set_name }}", members: [ { _id : 0, host :"{{ bdb_hosts[bdb_hosts|length-1]['name'] }}:{{ mongodb_port }}" } ] } ) +sleep(5000); +{% for host in bdb_hosts %} +{%- if ansible_hostname != host["name"] -%} +rs.add("{{ host["name"] }}:{{ mongodb_port }}"); +{% endif %} +{%- endfor -%} \ No newline at end of file diff --git a/pkg/configuration/vars/bdb-config.yml b/pkg/configuration/vars/bdb-config.yml new file mode 100644 index 00000000..952738b2 --- /dev/null +++ b/pkg/configuration/vars/bdb-config.yml @@ -0,0 +1,13 @@ +--- +deploy_docker: false #[true, false] +docker_replset_size: 1 +upstart: "/bigchaindb/scripts/bootstrap.sh" +bdb_hosts: + - name: "config-node" + box: + name: "ubuntu/xenial64" + ram: "2048" + vcpus: "2" + network: + ip: "10.20.30.40" + type: "private_network" \ No newline at end of file diff --git a/pkg/scripts/bootstrap_helper.sh b/pkg/scripts/bootstrap_helper.sh index 2c8abd32..8afb4d7e 100755 --- a/pkg/scripts/bootstrap_helper.sh +++ b/pkg/scripts/bootstrap_helper.sh @@ -28,7 +28,7 @@ validate_os_version_and_deps(){ fi ;; fedora) - dnf install bc -y > /dev/null 2>&1 + dnf install bc python2-dnf libselinux-python -y > /dev/null 2>&1 if [[ ($(echo $3 | bc) > $MINIMUM_FEDORA_VERSION) || ($(echo $3 | bc) == $MINIMUM_FEDORA_VERSION) ]]; then rpm -q "${OS_DEPENDENCIES[@]}" > /dev/null 2>&1 @@ -71,20 +71,22 @@ install_dependencies() { # multiple dependencies) install_deps_deb() { echo "Installing Dependencies..." + apt-get update -y apt-get install -y software-properties-common apt-add-repository ppa:ansible/ansible - apt-get update - apt-get install -y --force-yes ansible + apt-get update -y + apt-get install -y "${OS_DEPENDENCIES[@]}" } install_deps_centos() { echo "Installing Dependencies..." yum install epel-release -y yum install -y https://centos7.iuscommunity.org/ius-release.rpm - yum install ansible -y + yum install "${OS_DEPENDENCIES[@]}" -y } install_deps_fedora() { echo "Installing Dependencies..." export LC_ALL=C dnf makecache - dnf -y install ansible python2-dnf -} \ No newline at end of file + echo "${OS_DEPENDENCIES[@]}" + dnf -y install "${OS_DEPENDENCIES[@]}" +}