Ansible The Best Tool For Blockchain Developers To Deploy

0
32

As a blockchain developer, most of my work is an MVP for startups, POC for academic research or an on-premise system for governmental institutions. When someone asks me to make a real-life production network, I feel a bit nervous. How to handle the deployments? How to make it scaleable? How many nodes should I create? Handling the blockchain network needs many configurations, files and commands—this why I am going to introduce an awesome tool to manage your blockchain DevOps cycle.

What is Ansible?

Ansible is an open-source management tool used to automate tasks using a playbook The playbook is a .yaml file where you can write your code as blocks in an easy way to write and read even if you are not aware of the YAML files syntax. Example

---
- name: Automate some tasks
hosts: centos
become: yes
tasks:
- name: Create A New Directory
file:
path: /opt/newDirectory
state: directory
owner: root
mode: "777"
recurse: yes
- name: Copy File
copy:
src: ./run.py
dest: /opt/newDirectory/run.py
mode: a+x

And that’s it! I don’t think I need to explain it is easy to read. You can deploy this code on any running instance. I use it with amazon ec2 instances. Moreover, Ansible has roles. Roles are a set of tasks to accomplish something like installing Java on your deployed instance, configure some mentoring nodes like Prometheus or Grafana. You cand find a list of roles to use here. Ansible could be used for the CI/CD of your blockchain as we don’t have many tools for blockchain. You can save such a time if you automated the smart contract migration/deployment tasks. And same for modifying the blockchain network like adding a new peer, new nodes…etc

Ansible With The Blockchain

The first time I discovered Ansible was with IBM Blockchain Platform. I had to make an on-premise deployment using Ansible playbook. Normally, to deploy IBM blockchain platform, you need to create twelve YAMLs file and modify them. You can find the detailed manual installation here. Then, it may take you more than one hour to customize your Blockchain than start building your network using IBM Platform GUI, which is a boring task for me to keep clicking and saving the credentials. To set up the default network in hyperledger fabric( One peer, One channel, One Order, One organization) It may take more than one hour if you are not familiar. You can find the detailed steps here. In the other hand, ansible installs IBM platform with only one line of command. Using the playbook.yaml (find playbook files for both Openshift and Kubernetes here.)

---
- name: Deploy IBM Blockchain Platform custom resource definitions
hosts: localhost
vars:
state: present
target: k8s
arch: amd64
namespace: ibpinfra
image_registry_password: <image_registry_password>
image_registry_email: <image_registry_email>
wait_timeout: 3600
roles:
- ibm.blockchain_platform.crds

- name: Deploy IBM Blockchain Platform console
hosts: localhost
vars:
state: present
target: k8s
arch: amd64
namespace: <namespace>
image_registry_password: <image_registry_password>
image_registry_email: <image_registry_email>
console_domain: <console_domain>
console_email: <console_email>
console_default_password: <console_default_password>
wait_timeout: 3600
roles:
- ibm.blockchain_platform.console

Same for the Hyperledger fabric network you can create ordering service using the playbook

---
- name: Create components for an ordering organization
hosts: localhost
vars:
state: present
organization_name: "{{ ordering_org_name }}"
organization_msp_id: "{{ ordering_service_msp }}"
vars_files:
- common-vars.yml
- ordering-org-vars.yml
roles:
- ibm.blockchain_platform.ordering_organization

Find all hyperledger fabric component automation here. The scripts are ready to be implemented within IBM blockchain platform. You can modify the playbook as much as you want and keep your automate tasks to save time in future projects. Before working with hyperledger fabric, I had a project using hyperledger besu. The deployment for production using IBFT2 was so complicated, and I didn’t know ansible than. I wrote an article about IBFT2 production deployment. Fortunately, Hyperledger besu have an easy way to be deployed for production with ansible. Hyperledger besu is one of my favourite Blockchain as they use proof of authority consensus algorithm. The blockchain network for production needs two boot-node and other six nodes for validation. You can read the details from the official documentation. All tasks could be automated using Ansible.

To learn more about Ansible, I recommend these tutorials:

Ansible is not a tool designed mainly for the blockchain. It is used for automation. In general, we could use it to automate any complicated task in our work than share it as a roles to make our life much easier.

Join Coinmonks Telegram group and learn about crypto trading and investing

Also, Read


Ansible The Best Tool For Blockchain Developers To Deploy was originally published in Coinmonks on Medium, where people are continuing the conversation by highlighting and responding to this story.