1111 set_fact :
1212 volumes : []
1313
14+ - name : " Set the nodes"
15+ set_fact :
16+ couchdb_nodes : []
17+
1418- name : check if db credentials are valid for CouchDB
1519 fail : msg="The db provider in your {{ hosts_dir }}/group_vars/all is {{ db.provider }}, it has to be CouchDB, pls double check"
1620 when : db.provider != "CouchDB"
8892 force_basic_auth : yes
8993 when : (create_users_db.status == 404) and (inventory_hostname == coordinator) and (couchdb.version is version_compare('2.0','>='))
9094
95+ - name : check whether couchdb is clustered
96+ uri :
97+ url : " {{ db.protocol }}://{{ ansible_host }}:{{ db.port }}/_cluster_setup"
98+ method : GET
99+ status_code : 200
100+ user : " {{ db.credentials.admin.user }}"
101+ password : " {{ db.credentials.admin.pass }}"
102+ force_basic_auth : yes
103+ register : cluster_state
104+ run_once : true
105+
91106- name : check clustered nodes
92107 uri :
93108 url : " {{ db.protocol }}://{{ ansible_host }}:{{ db.port }}/_membership"
99114 register : nodes_state
100115 run_once : true
101116
117+ - name : generates couchdb node name
118+ set_fact :
119+ couchdb_nodes : " {{ couchdb_nodes }} + [ 'couchdb@{{ item }}' ]"
120+ with_items : " {{ groups['db'] }}"
121+ run_once : true
122+
123+ - debug : var=couchdb_nodes
124+
102125- name : check if there is a new node
103126 set_fact :
104127 require_clustering : true
105128 when : item not in nodes_state.json.cluster_nodes
106- with_item : groups['db']
129+ with_items : " {{ couchdb_nodes }} "
107130 run_once : true
108131
109- - set_fact :
110- require_clustering : " {{ item }}"
111- loop : " {{ groups['db'] }}"
112- when : item not in nodes_state.json.cluster_nodes
132+ - debug : var=require_clustering
113133
114134- name : set node name
115135 set_fact :
152172 user : " {{ db.credentials.admin.user }}"
153173 password : " {{ db.credentials.admin.pass }}"
154174 force_basic_auth : yes
155- when : (inventory_hostname == coordinator) and (db.instances|int >= 2) and require_clustering is defined
175+ when : (inventory_hostname == coordinator) and (db.instances|int >= 2) and (cluster_state.json.state != "cluster_finished")
0 commit comments