-
Notifications
You must be signed in to change notification settings - Fork 63
/
start-network.yml
244 lines (188 loc) · 12.8 KB
/
start-network.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
---
- hosts: nodes
tasks:
- name: Clean all previous dockers, if any
raw: "docker rm -f $(docker ps -a | grep {{ domain }} | awk '{print $1};')"
ignore_errors: true
- name: Clean all docker volumes
raw: "docker volume rm $(docker volume ls -qf dangling=true)"
ignore_errors: true
- name: Findout UID
raw: "id -u {{ ansible_user }}"
register: ansible_uid
- name: Findout GID
raw: "id -g {{ ansible_user }}"
register: ansible_gid
- name: Clean all help-scripts, if any
file:
dest: "{{ item }}"
state: absent
loop:
- "{{ fabric_starter_workdir }}/start-node.sh"
- "{{ fabric_starter_workdir }}/stop-node.sh"
- set_fact:
ansible_user_uid: "{{ ansible_uid.stdout | int }}"
ansible_user_gid: "{{ ansible_gid.stdout | int }}"
- name: Starting kafka-zookeppers
block:
- name: Transfer zookeeper configuration file for docker compose
template:
src: "docker-compose-templates/docker-composetemplate-zookeeper.yaml"
dest: "{{ docker_artifacts }}/docker-compose-zookeeper-{{ inventory_hostname_short }}.yaml"
- name: Start kafka-zookeper
raw: "docker-compose -f {{ docker_artifacts }}/docker-compose-zookeeper-{{ inventory_hostname_short }}.yaml up -d 2>&1"
- name: Generate init-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/start-node.sh"
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-zookeeper-{{ inventory_hostname_short }}.yaml up -d 2>&1"
create: yes
- name: Generate down-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/stop-node.sh"
insertbefore: BOF
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-zookeeper-{{ inventory_hostname_short }}.yaml down"
create: yes
- name: Let zookpeers select leader
raw: "docker logs $(docker ps | grep zookeeper | awk '{ print $1 }')"
register: docker_logs_output
until: '"LEADER ELECTION TOOK" in docker_logs_output.stdout'
retries: 15
delay: 1
when: "'zookeeper' in node_roles"
- name: Starting kafka-brokers
block:
- name: Transfer kafka-broker configuration file for docker compose
template:
src: "docker-compose-templates/docker-composetemplate-kafka-broker.yaml"
dest: "{{ docker_artifacts }}/docker-compose-kafka-broker-{{ inventory_hostname_short }}.yaml"
- name: Start kafka-broker
raw: "docker-compose -f {{ docker_artifacts }}/docker-compose-kafka-broker-{{ inventory_hostname_short }}.yaml up -d 2>&1"
- name: Generate init-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/start-node.sh"
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-kafka-broker-{{ inventory_hostname_short }}.yaml up -d 2>&1"
create: yes
- name: Generate down-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/stop-node.sh"
insertbefore: BOF
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-kafka-broker-{{ inventory_hostname_short }}.yaml down"
create: yes
- name: Let kafka-cluster start
raw: "docker logs $(docker ps | grep kafka-broker | awk '{ print $1 }')"
register: docker_logs_output
until: '"started" in docker_logs_output.stdout'
retries: 15
delay: 1
when: "'kafka_broker' in node_roles"
- name: Starting orderer
block:
- name: Start orderer
raw: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ domain }}.yaml up -d 2>&1"
- name: Generate init-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/start-node.sh"
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ domain }}.yaml up -d 2>&1"
create: yes
- name: Generate down-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/stop-node.sh"
insertbefore: BOF
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ domain }}.yaml down"
create: yes
# - name: Create all folders for rsync..
# file:
# path: "./artifacts/{{ item.to }}"
# state: directory
# loop: "{{ files_to_rsync_nodes_phase1 }}"
# delegate_to: localhost
#
# - name: Synchronize genrated block files (artifacts)
# synchronize: src="{{ fabric_artifacts }}/{{ item.from }}" dest="./artifacts/{{ item.to }}" mode=pull recursive=yes
# loop: "{{ files_to_rsync_nodes_phase1 }}"
when: "'orderer' in node_roles"
- name: Starting peers
block:
- name: Create all folders for rsync..
file:
path: "{{ fabric_artifacts }}/{{ item.to }}"
state: directory
loop: "{{ files_to_rsync_nodes_phase1 }}"
when: "orderer_count is not defined or orderer_count <= 1"
- name: Synchronize genrated block files (artifacts)
synchronize: src="./artifacts/{{ item.from }}" dest="{{ fabric_artifacts }}/{{ item.to }}" recursive=yes
loop: "{{ files_to_rsync_nodes_phase1 }}"
when: "orderer_count is not defined or orderer_count <= 1"
- name: Synchronize www-client folder
synchronize: src="www-client" dest="{{ fabric_starter_workdir }}" recursive=yes
- name: Start docker containers
raw: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ org }}.yaml up -d 2>&1"
- name: Generate init-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/start-node.sh"
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ org }}.yaml up -d 2>&1"
create: yes
- name: Generate down-script..
lineinfile:
path: "{{ fabric_starter_workdir }}/stop-node.sh"
insertbefore: BOF
line: "docker-compose -f {{ docker_artifacts }}/docker-compose-{{ org }}.yaml down"
create: yes
- name: Install chaincode
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm 'cli.{{ org }}.{{ domain }}' bash -c 'CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer chaincode install -n {{ chaincode_common_name }} -v {{ chaincode_version }} -p {{ chaincode_common_name }} -l {{ chaincode_lang }} && CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer chaincode install -n {{ chaincode_common_name }} -v {{ chaincode_version }} -p {{ chaincode_common_name }} -l {{ chaincode_lang }}'"
- name: Install chaincode for additional cahnnels, if any
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm 'cli.{{ org }}.{{ domain }}' bash -c 'CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer chaincode install -n {{ chaincode_bilateral_name }} -v {{ chaincode_version }} -p {{ chaincode_bilateral_name }} -l {{ chaincode_lang }} && CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer chaincode install -n {{ chaincode_bilateral_name }} -v {{ chaincode_version }} -p {{ chaincode_bilateral_name }} -l {{ chaincode_lang }}'"
when: "additional_channels is defined"
when: "'peer' in node_roles"
- name: Creating channels
block:
- name: Creating common channels
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "peer channel create -o orderer{{ orderer_id | default() }}.{{ domain }}:7050 -c common -f /etc/hyperledger/artifacts/channel/common.tx --tls --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ domain }}/orderers/orderer{{ orderer_id | default() }}.{{ domain }}/tls/ca.crt"'
- name: Creating other channels, if any
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "peer channel create -o orderer{{ orderer_id | default() }}.{{ domain }}:7050 -c {{ item.name }} -f /etc/hyperledger/artifacts/channel/{{ item.name }}.tx --tls --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ domain }}/orderers/orderer{{ orderer_id | default() }}.{{ domain }}/tls/ca.crt"'
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
- name: Changing ownership of channel block files
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ domain }}" bash -c "chown -R {{ ansible_user_uid }}:{{ ansible_user_gid }} ."'
- name: Joining common channel
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer channel join -b common.block"'
- raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer channel join -b common.block"'
- name: Joining other channels, if any
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer channel join -b {{ item.name }}.block"'
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
- raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer channel join -b {{ item.name }}.block"'
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
- name: Instantiating chaincode for common channel
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm cli.{{ org }}.{{ domain }} bash -c 'CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer chaincode instantiate -n {{ chaincode_common_name }} -v {{ chaincode_version }} -c {{ chanicode_common_init | to_json }} -o orderer{{ orderer_id | default() }}.{{ domain }}:7050 -C common --tls --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ domain }}/orderers/orderer{{ orderer_id | default() }}.{{ domain }}/tls/ca.crt'"
- name: Instantiating chaincode for other channels, if any
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm cli.{{ org }}.{{ domain }} bash -c 'CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer chaincode instantiate -n {{ chaincode_bilateral_name }} -v {{ chaincode_version }} -c {{ chanicode_bilateral_init | to_json }} -o orderer{{ orderer_id | default() }}.{{ domain }}:7050 -C {{ item.name }} --tls --cafile /etc/hyperledger/artifacts/crypto-config/ordererOrganizations/{{ domain }}/orderers/orderer{{ orderer_id | default() }}.{{ domain }}/tls/ca.crt'"
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
- name: Create all folders for rsync..
file:
path: "./artifacts/{{ item.to }}"
state: directory
loop: "{{ files_to_rsync_nodes_phase2 }}"
delegate_to: localhost
- name: Synchronize genrated block files (artifacts)
synchronize: src="{{ fabric_artifacts }}/{{ item.from }}" dest="./artifacts/{{ item.to }}" mode=pull recursive=yes
loop: "{{ files_to_rsync_nodes_phase2 }}"
when: "'root_peer' in node_roles"
- name: Joining channels
block:
- name: Synchronize genrated block files (artifacts)
become: true
synchronize: src="artifacts" dest="{{ fabric_starter_workdir }}" recursive=yes
- name: Joining common channel
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer channel join -b common.block"'
- raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer channel join -b common.block"'
- name: Joining other channels, if any
raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer0.{{ org }}.{{ domain }}:7051 peer channel join -b {{ item.name }}.block"'
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
- raw: 'docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml run --rm "cli.{{ org }}.{{ domain }}" bash -c "CORE_PEER_ADDRESS=peer1.{{ org }}.{{ domain }}:7051 peer channel join -b {{ item.name }}.block"'
loop: "{{ additional_channels }}"
when: "additional_channels is defined"
when: "'root_peer' not in node_roles and 'peer' in node_roles"