|
19 | 19 |
|
20 | 20 | - name: set the coordinator to the first node |
21 | 21 | set_fact: |
22 | | - coordinator: "{{ groups['db'][0] }}" |
| 22 | + coordinator: "{{ couchdb_coordinator | default(groups['db'][0]) }}" |
23 | 23 |
|
24 | 24 | - name: "Set the volumes" |
25 | 25 | set_fact: |
|
49 | 49 | volumes: "{{ volumes }} + [ '{{ db.persist_path }}:/opt/couchdb/data' ]" |
50 | 50 | when: db.persist_path |
51 | 51 |
|
52 | | -- include_tasks: gen_erl_cookie.yml |
53 | | - when: (db.instances|int >= 2) |
54 | | - |
55 | | -- name: "set the erlang cookie volume" |
| 52 | +- name: "mount conf directory for db configuration" |
56 | 53 | set_fact: |
57 | | - volumes: "{{ volumes }} + [ '{{ config_root_dir }}/erlang.cookie:/opt/couchdb/.erlang.cookie' ]" |
58 | | - when: (db.instances|int >= 2) |
| 54 | + volumes: "{{ volumes }} + [ '{{ db_confdir }}:/opt/couchdb/etc' ]" |
| 55 | + when: db_confdir is defined |
| 56 | + |
| 57 | +- name: ensure CouchDB config directory exists |
| 58 | + file: |
| 59 | + path: "{{ db_confdir }}" |
| 60 | + state: directory |
| 61 | + become: "{{ db.dir.become }}" |
| 62 | + when: db_confdir is defined |
| 63 | + |
| 64 | +- name: synchronize default configuration files from local to remote in CouchDB config directory |
| 65 | + synchronize: |
| 66 | + src: "files/" |
| 67 | + dest: "{{ db_confdir }}" |
| 68 | + delete: yes |
| 69 | + recursive: yes |
| 70 | + become: "{{ db.dir.become }}" |
| 71 | + when: db_confdir is defined |
59 | 72 |
|
60 | 73 | - name: "(re)start CouchDB from '{{ couchdb_image }} ' " |
61 | 74 | vars: |
|
115 | 128 | password: "{{ db.credentials.admin.pass }}" |
116 | 129 | force_basic_auth: yes |
117 | 130 | register: cluster_state |
118 | | - run_once: true |
| 131 | + delegate_to: "{{ coordinator }}" |
119 | 132 |
|
120 | 133 | - name: check clustered nodes |
121 | 134 | uri: |
|
126 | 139 | password: "{{ db.credentials.admin.pass }}" |
127 | 140 | force_basic_auth: yes |
128 | 141 | register: nodes_state |
129 | | - run_once: true |
| 142 | + delegate_to: "{{ coordinator }}" |
130 | 143 |
|
131 | 144 | - name: generates couchdb node name |
132 | 145 | set_fact: |
|
184 | 197 | force_basic_auth: yes |
185 | 198 | when: (inventory_hostname == coordinator) and (db.instances|int >= 2) and (cluster_state.json.state != "cluster_finished") |
186 | 199 |
|
| 200 | +- name: check whether the cluster is setup or not |
| 201 | + uri: |
| 202 | + url: "{{ db.protocol }}://{{ ansible_host }}:{{ db.port }}/_cluster_setup" |
| 203 | + method: GET |
| 204 | + status_code: 200 |
| 205 | + user: "{{ db.credentials.admin.user }}" |
| 206 | + password: "{{ db.credentials.admin.pass }}" |
| 207 | + force_basic_auth: yes |
| 208 | + register: cluster_state |
| 209 | + run_once: true |
0 commit comments