Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an way for complete specifying the peer crypto configurations when creating a new peer using the collection. #75

Merged
merged 5 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 69 additions & 2 deletions plugins/modules/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,63 @@
label: Org1 CA label
pin: 12345678

- name: Create multiple peers with advanced crypto configuration (CSR Hosts with SANs) and K8S builder
hyperledger.fabric_ansible_collection.peer:
state: present
api_endpoint: https://console.example.org:32000
api_authtype: basic
api_key: xxxxxxxx
api_secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
api_token_endpoint: "{{ api_token_endpoint | default(omit) }}"
api_timeout: "{{ api_timeout | default(omit) }}"
name: "Org Peer{{ item }}"
msp_id: "Org1MSP"
state_db: "{{ peer_state_db }}"
resources: "{{ peer_resources | default(omit) }}"
storage: "{{ peer_storage | default(omit) }}"
version: "{{ peer_version | default(omit) }}"
zone: "{{ peer_zones[peer_idx] | default(omit) }}"
wait_timeout: "{{ wait_timeout | default(omit) }}"
crypto:
enrollment:
component:
admin_certs:
- "{{ endorsing_organization_org_admin.enrolled_identity.cert | default(omit) }}"
ca:
host: "console_namespace-ca-ca.your.own.domain.localh.st"
port: "443"
name: "ca"
tls_cert: "{{ organization_ca.certificate_authority.pem }}"
enroll_id: "{{ peer_enrollment_id }}{{ item }}"
enroll_secret: "{{ peer_enrollment_secret }}"
tlsca:
host: "console_namespace-ca-ca.your.own.domain.localh.st"
port: "443"
name: "tlsca"
tls_cert: "{{ organization_ca.certificate_authority.pem }}"
enroll_id: "{{ peer_enrollment_id }}{{ item }}"
enroll_secret: "{{ peer_enrollment_secret }}"
csr_hosts:
- peers.your.own.domain.localh.st
- peer.your.own.domain.localh.st
- "127.0.0.1"
config_override:
chaincode:
externalBuilders:
- name: k8s_builder
path: /opt/hyperledger/k8s_builder
propagateEnvironment:
- CORE_PEER_ID
- FABRIC_K8S_BUILDER_DEBUG
- FABRIC_K8S_BUILDER_NAMESPACE
- FABRIC_K8S_BUILDER_OBJECT_NAME_PREFIX
- FABRIC_K8S_BUILDER_SERVICE_ACCOUNT
- KUBERNETES_SERVICE_HOST
- KUBERNETES_SERVICE_PORT
loop: "{{ range(1, number_of_peers|int + 1, 1) | list }}"
loop_control:
index_var: peer_idx

- name: Destroy peer
hyperledger.fabric_ansible_collection.peer:
state: absent
Expand Down Expand Up @@ -781,8 +838,18 @@ def main():
del expected_peer['resources']
del expected_peer['storage']

# Get the config.
expected_peer['crypto'] = get_crypto(console, module)
# Get the crypto configuration.
# When configuring cryptography in your Ansible playbook for the peer component creating, you have two
# choices: provide all the necessary settings directly, or use a Certificate Authority (CA). These options
# are mutually exclusive, meaning youcan only choose one. If you opt to use a CA, ensure you provide all
# the required CA details, including its name, to avoid errors.
# OBS: (Without this, the get_crypto(console, module) will return an error because the
# ca name won ´t be provided under certificate_authority ansible parameter.
crypto = module.params['crypto']
if crypto is not None:
expected_peer['crypto'] = crypto
else:
expected_peer['crypto'] = get_crypto(console, module)

# Create the peer.
peer = console.create_peer(expected_peer)
Expand Down