blob: b59c23d044be7cbe0cb2f006a7d17c834ce34251 [file] [log] [blame]
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements; and to You under the Apache License, Version 2.0.
---
# This role will run a CouchDB server on the db group
- name: "Set the coordinator to the first node"
set_fact:
coordinator: "{{ groups['db'][0] }}"
- name: check if db credentials are valid for CouchDB
fail: msg="The db provider in your {{ hosts_dir }}/group_vars/all is {{ db_provider }}, it has to be CouchDB, pls double check"
when: db_provider != "CouchDB"
- name: check for persistent disk
shell: df -h
register: disk_status
when: block_device is defined
- name: "set the volume_dir"
vars:
instance: "{{instances | selectattr('name', 'equalto', 'db') | list | first}}"
set_fact:
volume_dir: "{{ instance.volume.fsmount | default( '/mnt/' + group_names|first, true ) }}:/usr/local/var/lib/couchdb"
when: (block_device is defined) and (block_device in disk_status.stdout)
- name: "(re)start CouchDB from '{{ couchdb_image }} ' "
vars:
couchdb_image: "{{ couchdb.docker_image | default('apache/couchdb:' ~ couchdb.version ) }}"
docker_container:
name: couchdb
image: "{{ couchdb_image }}"
state: started
recreate: true
restart_policy: "{{ docker.restart.policy }}"
volumes: "{{volume_dir | default([])}}"
ports:
- "{{ db_port }}:5984"
- "4369:4369"
- "9100:9100"
env:
COUCHDB_USER: "{{ db_username }}"
COUCHDB_PASSWORD: "{{ db_password }}"
NODENAME: "{{ ansible_host }}"
pull: "{{ couchdb.pull_couchdb | default(true) }}"
retries: "{{ docker.pull.retries }}"
delay: "{{ docker.pull.delay }}"
- name: wait until CouchDB in this host is up and running
uri:
url: "{{ db_protocol }}://{{ ansible_host }}:{{ db_port }}/_utils/"
register: result
until: result.status == 200
retries: 12
delay: 5
- name: create '_users' database for singleton mode
uri:
url: "{{ db_protocol }}://{{ ansible_host }}:{{ db_port }}/_users"
method: PUT
status_code: 201
user: "{{ db_username }}"
password: "{{ db_password }}"
force_basic_auth: yes
when: (couchdb.version|version_compare('2.0','>=')) and (db.instances|int == 1)
- name: enable the cluster setup mode
uri:
url: "{{ db_protocol }}://{{ ansible_host }}:{{ db_port }}/_cluster_setup"
method: POST
body: >
{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "{{ db_username }}", "password":"{{ db_password }}", "port": {{ db_port }}, "node_count": "{{ groups['db'] | length }}", "remote_node": "{{ ansible_host }}", "remote_current_user": "{{ db_username }}", "remote_current_password": "{{ db_password }}"}
body_format: json
status_code: 201
user: "{{ db_username }}"
password: "{{ db_password }}"
force_basic_auth: yes
when: (inventory_hostname == coordinator) and (db.instances|int >= 2)
- name: add remote nodes to the cluster
uri:
url: "{{ db_protocol }}://{{ coordinator }}:{{ db_port }}/_cluster_setup"
method: POST
body: >
{"action": "add_node", "host":"{{ ansible_host }}", "port": {{ db_port }}, "username": "{{ db_username }}", "password":"{{ db_password }}"}
body_format: json
status_code: 201
user: "{{ db_username }}"
password: "{{ db_password }}"
force_basic_auth: yes
when: (inventory_hostname != coordinator) and (db.instances|int >= 2)
- name: finish the cluster setup mode
uri:
url: "{{ db_protocol }}://{{ ansible_host }}:{{ db_port }}/_cluster_setup"
method: POST
body: >
{"action": "finish_cluster"}
body_format: json
status_code: 201
user: "{{ db_username }}"
password: "{{ db_password }}"
force_basic_auth: yes
when: (inventory_hostname == coordinator) and (db.instances|int >= 2)