forked from minhlh/Ansible-Fabric-Starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config-network.yml
201 lines (155 loc) · 7.02 KB
/
config-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
---
- hosts: localhost
tasks:
- name: Clean local artifacts folder
file:
path: artifacts
state: "{{ item }}"
loop:
- "absent"
- "directory"
- import_playbook: start-monitoring.yml
- hosts: nodes
tasks:
- name: Perfom check for 'newcomers' flag
fail:
msg: "newcomers flag is defined. Are you sure, you want to destroy existing network? ..Aborting."
tags:
- safetycheck
when: "newcomers is defined"
- name: Clean all previous dockers, if any
raw: "docker rm -f $(docker ps -a | grep {{ global_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: Clean all chaincode images
raw: "docker image rm $(docker image ls | grep {{ global_domain }} | awk '{print $1};')"
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
- set_fact:
ansible_user_uid: "{{ ansible_uid.stdout | int }}"
ansible_user_gid: "{{ ansible_gid.stdout | int }}"
- name: Clean all config folders
become: true
file:
path: "{{ item }}"
state: absent
loop:
- "{{ fabric_starter_workdir }}"
- name: Ensure all folders exist
file:
dest: "{{ item }}"
state: directory
loop: "{{ fabric_artifacts_folders }}"
- name: Transfer common configuration files
template:
src: "{{ item.from }}"
dest: "{{ item.to }}"
loop: "{{ fabric_templates }}"
- name: Configure peer
block:
- name: Transfer chaincode
template:
src: "{{ item.from }}"
dest: "{{ item.to }}"
mode: a+x
loop: "{{ chaincode_templates }}"
- name: Transfer chaincode binary
synchronize:
src: "templates/chaincode/chaincode.tar.gz"
dest: "{{ chaincode }}"
- name: Transfer collections config
template:
src: "collections_config.json"
dest: "{{ collections_config_path }}"
when: "collections_config_path != ''"
- name: Transfer peer configuration files
template:
src: "{{ item.from }}"
dest: "{{ item.to }}"
loop: "{{ peer_templates }}"
- name: Start cli container without crypto volumes
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ org }}.yaml up -d 'cliNoCryptoVolume.{{ org }}.{{ global_domain }}'"
- name: Generate crypto material with cryptogen
raw: "docker exec 'cliNoCryptoVolume.{{ org }}.{{ global_domain }}' bash -c 'cryptogen generate --config=cryptogen-{{ org }}.yaml'"
- name: Generating orgConfig.json
raw: 'docker exec "cliNoCryptoVolume.{{ org }}.{{ global_domain }}" bash -c "FABRIC_CFG_PATH=./ configtxgen -printOrg {{ org }}MSP > {{ org }}Config.json"'
- name: Changing artifacts ownership
raw: "docker exec 'cliNoCryptoVolume.{{ org }}.{{ global_domain }}' bash -c 'chown -R {{ ansible_user_uid }}:{{ ansible_user_gid }} .'"
- name: Create all folders for rsync..
file:
path: "./artifacts/{{ item.to }}"
state: directory
loop: "{{ files_to_rsync_orderer }}"
delegate_to: localhost
- name: Synchronize artifacts
synchronize: src="{{ fabric_artifacts }}/{{ item.from }}" dest="./artifacts/{{ item.to }}" mode=pull recursive=yes
loop: "{{ files_to_rsync_orderer }}"
when: "'peer' in node_roles"
- name: Sync orderer configs
block:
- name: Synchronize artifacts back to orderer
synchronize: src="artifacts" dest="{{ fabric_starter_workdir }}" recursive=yes
- name: Transfer orderer configuration files
template:
src: "{{ item.from }}"
dest: "{{ item.to }}"
loop: "{{ orderer_templates }}"
when: "'orderer' in node_roles"
- name: Configure orderer
block:
- name: Start cli orderer container
raw: "docker-compose --file {{ docker_artifacts }}/docker-compose-{{ global_domain }}.yaml up -d 'cli.{{ global_domain }}'"
- name: Generating crypto material with cryptogen
raw: 'docker exec "cli.{{ global_domain }}" bash -c "cryptogen generate --config=cryptogen-{{ global_domain }}.yaml"'
- name: Generating orderer genesis block with configtxgen
raw: 'docker exec "cli.{{ global_domain }}" configtxgen -profile OrdererGenesisEtcdRaft -outputBlock ./channel/genesis.block -channelID byfn-sys-channel'
loop: "{{ global_channels }}"
when: "global_channels is defined"
- name: Changing artifacts file ownership
raw: 'docker exec "cli.{{ global_domain }}" bash -c "chown -R {{ ansible_user_uid }}:{{ ansible_user_gid }} ."'
- name: Generating channels config transactions, if any
raw: 'docker exec "cli.{{ global_domain }}" configtxgen -profile "{{ item.name }}" -outputCreateChannelTx "./channel/{{ item.name }}.tx" -channelID "{{ item.name }}"'
loop: "{{ global_channels }}"
when: "global_channels is defined"
- 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: "'root_orderer' in node_roles"
- hosts: nodes # Re-login to obtain facts
tasks:
- name: Create all folders for rsync..
file:
path: "{{ fabric_artifacts }}/{{ item.to }}"
state: directory
loop: "{{ files_to_rsync_nodes_phase1 }}"
when: "'orderer' in node_roles and 'root_orderer' not in node_roles"
- 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' in node_roles and 'root_orderer' not in node_roles"
- name: Rename generated private keys to server.key
shell: find {{ fabric_artifacts }}/crypto-config -iname "*_sk*" -exec bash -c 'cp $0 $(echo $0 | sed -e "s/[^/]*_sk/server.key/")' {} \;
when: "'peer' in node_roles or 'orderer' in node_roles"
- name: Generate anchor peers updates
block:
- name: Generating anchor peer updates for other channels, if defined
raw: 'docker exec -e FABRIC_CFG_PATH=/etc/hyperledger/artifacts "cliNoCryptoVolume.{{ org }}.{{ global_domain }}" configtxgen -profile "{{ item.name }}" -outputAnchorPeersUpdate ./channel/{{ org }}MSPanchors-{{ item.name }}.tx -channelID "{{ item.name }}" -asOrg {{ org }}MSP'
loop: "{{ global_channels }}"
when: "global_channels is defined and org in item.particapants"
- name: Changing artifacts ownership
raw: "docker exec 'cliNoCryptoVolume.{{ org }}.{{ global_domain }}' bash -c 'chown -R {{ ansible_user_uid }}:{{ ansible_user_gid }} .'"
when: "'peer' in node_roles"
- import_playbook: start-network.yml