Got Ansible to install, config & run BigchainDB

This commit is contained in:
troymc 2016-08-29 14:50:22 +02:00
parent c243a77a18
commit 46e70d0c7f
4 changed files with 61 additions and 11 deletions

View File

@ -0,0 +1,3 @@
#!/bin/bash
bigchaindb -y start &
disown

View File

@ -1,5 +1,5 @@
---
# ansible/roles/bcdb_base/tasks/main.yml
# ansible/roles/bigchaindb/tasks/main.yml
# Note: "become: true" basically means "become root user for this task" i.e. sudo <cmd>
# See https://docs.ansible.com/ansible/become.html
@ -25,6 +25,39 @@
pip: executable=pip3 name=setuptools state=latest
become: true
- name: Install BigchainDB from PyPI using sudo pip3 install bigchaindb
pip: executable=pip3 name=bigchaindb state=latest
become: true
- name: Gather facts about the file ~/.bigchaindb
stat: path={{ ansible_env.HOME }}/.bigchaindb
register: home_bigchaindb_config_file
- name: If ~/.bigchaindb doesn't exist, generate a default BigchainDB config file there
shell: bigchaindb -y configure
when: not home_bigchaindb_config_file.stat.exists
- name: Look up all processes with 'bigchaindb' in their name
shell: pgrep bigchaindb
ignore_errors: true
changed_when: false
register: pgrep_bigchaindb
# pgrep_bigchaindb.rc (return code) should be 0 if a bigchaindb process is already running
- name: Ensure a copy of start_bigchaindb.sh is on the remote host
copy: src=start_bigchaindb.sh dest=/tmp/start_bigchaindb.sh mode=0775
become: true
# Running BigchainDB in the background from Ansible is tricky, see:
# https://superuser.com/questions/870871/run-a-remote-script-application-in-detached-mode-in-ansible
- name: If BigchainDB isn't running then run it
command: /tmp/start_bigchaindb.sh
async: 45
poll: 0
when: pgrep_bigchaindb.rc != 0
# Notes about getting the latest version of pip3:
#
# The first way I tried to get the latest pip3 (commented-out below) didn't work.

View File

@ -23,14 +23,24 @@
file: path=/data state=directory owner=rethinkdb group=rethinkdb
become: true
- name: Gather facts about the file /data/metadata
stat: path=/data/metadata
register: data_metadata_file
- name: Gather facts about the file /tmp/created_on_run1
stat: path=/tmp/created_on_run1
register: file_created_on_run1
- name: Create /data/metadata file if it doesn't exist
file: path=/data/metadata state=touch owner=rethinkdb group=rethinkdb mode=0664
when: not data_metadata_file.stat.exists
- name: if the file /tmp/created_on_run1 doesn't exist then create /data/delete_me
file: path=/data/delete_me state=touch owner=rethinkdb group=rethinkdb
become: true
when: not file_created_on_run1.stat.exists
- name: if the file /tmp/created_on_run1 doesn't exist then do sudo rm -rf /data/*
shell: rm -rf /data/*
become: true
when: not file_created_on_run1.stat.exists
- name: if the file /tmp/created_on_run1 doesn't exist then create it
file: path=/tmp/created_on_run1 state=touch
become: true
when: not file_created_on_run1.stat.exists
# To enable starting RethinkDB on boot (on init.d systems),
# the config file must be put in /etc/rethinkdb/instances.d/
@ -43,8 +53,8 @@
template:
src=rethinkdb.conf.j2
dest=/etc/rethinkdb/instances.d/instance1.conf
owner=rethinkdb
group=rethinkdb
owner=root
group=root
mode=0664
become: true
register: config_file
@ -54,6 +64,8 @@
become: true
register: rethinkdb_started
- debug: var=rethinkdb_started
- debug: msg="The RethinkDB config file changed while RethinkDB was already running.
RethinkDB was not stopped and restarted. You must do that manually."
when: config_file.changed and (not rethinkdb_started.changed)

View File

@ -1,8 +1,10 @@
directory=/data
runuser=rethinkdb
rungroup=rethinkdb
bind=all
# The IP address of localhost is 127.0.0.1
bind-http=127.0.0.1
direct-io
#bind-http=127.0.0.1
# direct-io
# List of *other* hostnames in the cluster:
# join=hostname1:29015
# join=hostname2:29015