-
Notifications
You must be signed in to change notification settings - Fork 0
/
05-create-channel.yaml
96 lines (90 loc) · 4.66 KB
/
05-create-channel.yaml
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
---
- name: Create channels
hosts: localhost
vars_files:
- vars/common.yaml
- vars/organizations.yaml
- vars/channels.yaml
vars:
# os_org_name: os
# creator_org_name: org1
# channel_name: samplechannel1
os_org: "{{ vars['ordering_organization'][os_org_name] }}"
creator_org: "{{ vars['peer_organizations'][creator_org_name] }}"
ordering_service_msp_admin: "{{ wallet_path }}/{{ os_org.msp.admin }}.json"
creator_org_msp_admin: "{{ wallet_path }}/{{ creator_org.msp.admin }}.json"
channel_policies_dir: "{{ channel_policies_path }}/{{ channel_name }}"
channel_config_file: "{{ playbook_dir }}/vars/channels.yaml"
org_config_file: "{{ playbook_dir }}/vars/organizations.yaml"
tasks:
- name: Check to see if the channel already exists
ibm.blockchain_platform.channel_block:
api_endpoint: "{{ os_org.console.api_endpoint }}"
api_authtype: "{{ os_org.console.api_authtype }}"
api_key: "{{ os_org.console.api_key | default(omit) }}"
api_secret: "{{ os_org.console.api_secret | default(omit)}}"
operation: fetch
ordering_service: "{{ os_org.orderer.name }}"
identity: "{{ ordering_service_msp_admin }}"
msp_id: "{{ os_org.msp.id }}"
name: "{{ channel_name }}"
target: "0"
path: "{{ channel_config_path }}/{{ channel_name }}_genesis_block.bin"
register: result
ignore_errors: true
- name: Exit channel creation if it already exists
meta: end_play
when: result.msg is not defined or 'NOT_FOUND' not in result.msg
- shell: |
ORGS=$(yq r "{{ channel_config_file }}" --printMode p "channels.{{ channel_name }}.members.*" | awk -F "." '{print $4}')
for org in $ORGS; do yq r "{{ org_config_file }}" "peer_organizations.$org.msp.name"; done
register: channel_member_result
- set_fact:
channel_members: "{{ channel_member_result.stdout_lines }}"
- name: Create the configuration update for the new channel
ibm.blockchain_platform.channel_config:
api_endpoint: "{{ creator_org.console.api_endpoint }}"
api_authtype: "{{ creator_org.console.api_authtype }}"
api_key: "{{ creator_org.console.api_key | default(omit) }}"
api_secret: "{{ creator_org.console.api_secret | default(omit)}}"
operation: create
name: "{{ channel_name }}"
path: "{{ channel_config_path }}/{{ channel_name }}_config_update.bin"
organizations: "{{ channel_members }}"
capabilities:
application: "{{ vars['channels'][channel_name]['capabilities']['application'] | default('V2_0') }}"
policies:
Admins: "{{ lookup('file', '{{ channel_policies_dir }}/admins-policy.yaml') | from_yaml }}"
Readers: "{{ lookup('file', '{{ channel_policies_dir }}/readers-policy.yaml') | from_yaml }}"
Writers: "{{ lookup('file', '{{ channel_policies_dir }}/writers-policy.yaml') | from_yaml }}"
Endorsement: "{{ lookup('file', '{{ channel_policies_dir }}/default-cc-endorsers.yaml') | from_yaml }}"
LifecycleEndorsement: "{{ lookup('file', '{{ channel_policies_dir }}/cc-lifecycle.yaml') | from_yaml }}"
- name: Peer organizations signs the channel configuration update for the new channel
vars:
- org: "{{ peer_organizations[item] }}"
ibm.blockchain_platform.channel_config:
operation: sign_update
identity: "{{ wallet_path }}/{{ org.msp.admin }}.json"
msp_id: "{{ org.msp.id }}"
name: "{{ channel_name }}"
path: "{{ channel_config_path }}/{{ channel_name }}_config_update.bin"
loop: "{{ channels[channel_name].members.keys() | list }}"
- name: Ordering organization signs the channel configuration update for the new channel
ibm.blockchain_platform.channel_config:
operation: sign_update
identity: "{{ ordering_service_msp_admin }}"
msp_id: "{{ os_org.msp.id }}"
name: "{{ channel_name }}"
path: "{{ channel_config_path }}/{{ channel_name }}_config_update.bin"
- name: Apply the channel configuration update for the new channel
ibm.blockchain_platform.channel_config:
api_endpoint: "{{ creator_org.console.api_endpoint }}"
api_authtype: "{{ creator_org.console.api_authtype }}"
api_key: "{{ creator_org.console.api_key | default(omit) }}"
api_secret: "{{ creator_org.console.api_secret | default(omit)}}"
operation: apply_update
ordering_service: "{{ os_org.orderer.name }}"
identity: "{{ creator_org_msp_admin }}"
msp_id: "{{ creator_org.msp.id }}"
name: "{{ channel_name }}"
path: "{{ channel_config_path }}/{{ channel_name }}_config_update.bin"