-
Notifications
You must be signed in to change notification settings - Fork 297
Refactor Ansible role #2219
base: develop
Are you sure you want to change the base?
Refactor Ansible role #2219
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# Minimum total nodes is 6 (5f+1) in order for consensus to work properly. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still |
||
# | ||
# Default: 6 | ||
replicas: 6 | ||
iroha_replicas: 6 | ||
|
||
# Whether to use custom hostname for EACH container. | ||
# If set to `true`, Iroha peers will communicate using these hostnames. Hostnames should be set using | ||
|
@@ -11,7 +11,7 @@ replicas: 6 | |
# variable. Container and service names in Docker Compose files will be auto-generated. | ||
# | ||
# Default: false | ||
custom_hostnames: false | ||
iroha_custom_hostnames: false | ||
|
||
# Affects how Iroha peers are communicated. If set to `true`, Docker overlay network with that | ||
# name will be used. It must be created beforehand. The recommended way is to use Calico plugin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since Calico mentions are removed from iroha-docker/README.md, should it be removed from this file as well? |
||
|
@@ -21,29 +21,51 @@ custom_hostnames: false | |
# deployments for testing purposes. | ||
# | ||
# Default: false | ||
overlay_network: false | ||
iroha_overlay_network: false | ||
|
||
## Deployment configs | ||
container_basename: iroha | ||
iroha_container_basename: iroha | ||
# Path on a local machine for generated configs prior moving them on the remote | ||
config_local_dir: /tmp/iroha-ansible-conf | ||
iroha_config_local_dir: /tmp/iroha-ansible-conf | ||
# Path on a remote machine for generated configs | ||
deploy_dir: /opt/iroha-deploy | ||
iroha_deploy_dir: /opt/iroha-deploy | ||
# Overlay network name | ||
# If using overlay network plugin (like Calico) the network must be created prior running this role | ||
# The network will be created automatically if deploying locally or with `overlay_network` | ||
# The network will be created automatically if deploying locally or with `iroha_overlay_network` | ||
# set to `false` | ||
iroha_network_name: iroha-net | ||
|
||
# The role is incompatible with Iroha versions below RC2 since keys format has changed. | ||
# Apply the patch (files/old-keys-format.patch) if you need support for previous Iroha versions. | ||
iroha_docker_tag: 1.0.0_rc2 | ||
postgres_docker_tag: '9.5' | ||
iroha_docker_tag: 1.0.0_rc5 | ||
iroha_postgres_docker_tag: '9.5' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we bump version to postures 10? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The minimal supported version of Postgres is 9.5, AFAIK. It is used in CI to verify compatibility of each build. By using v9.5 we are confident that no breaking changes exist in later versions (though, they probably also play nice with Iroha. But we cannot say for sure). |
||
|
||
## The block of variables that toggles certain tasks of the role | ||
# Toggle tasks in `init-vars.yml` file. Will initialize variables for container names, | ||
# Iroha hostnames, etc. No configs will be changed. | ||
# Default: true | ||
iroha_init_vars: true | ||
# Toggle tasks in `config-gen.yml` file. Will generate new keys for Iroha with a new Genesis | ||
# Block | ||
# Default: true | ||
iroha_generate_init_configs: true | ||
# Toggle tasks in `deploy.yml` file. Enable if you just need to update Iroha configs and Docker | ||
# Compose file | ||
# Default: true | ||
iroha_update_runtime_configs: true | ||
|
||
# Toggles usage of a custom Genesis Block. Useful if you have custom roles, users, permissions, | ||
# etc. The role will fill your custom Genesis Block with Iroha peers while preserving everything | ||
# else. | ||
# Default: false | ||
iroha_custom_genesis_block: false | ||
# Path to the custom Genesis Block. Used only when `iroha_custom_genesis_block` set to `true` | ||
iroha_custom_genesis_block_path: '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use a single variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for me, it is not immediately obvious that setting just |
||
|
||
## Iroha config | ||
# This value will be used as a base peer port for Iroha container. E.g. setting `replicas` option to | ||
# This value will be used as a base peer port for Iroha container. E.g. setting `iroha_replicas` option to | ||
# 6 will generate Docker Compose file with port numbers starting from 10001 counting up to 10006. | ||
# If `custom_hostnames` set to `true` AND contains port numbers this option is ignored | ||
# If `iroha_custom_hostnames` set to `true` AND contains port numbers this option is ignored | ||
iroha_peer_port: 10001 | ||
# As above but for base Torii port | ||
iroha_torii_port: 50051 | ||
|
@@ -66,3 +88,4 @@ iroha_blockstore_path: /tmp/block_store | |
#iroha_mst_expiration_time: 1440 | ||
#iroha_max_rounds_delay: 3000 | ||
#iroha_stale_stream_max_rounds: 2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# handlers file for Iroha | ||
--- | ||
- name: restart Iroha | ||
docker_service: | ||
project_src: "{{ iroha_deploy_dir }}" | ||
pull: yes | ||
state: present | ||
recreate: always | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a newline and check other files. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,63 @@ | ||
- block: | ||
- set_fact: | ||
iroha_nodes: [] | ||
iroha_all_nodes: [] | ||
|
||
- name: generate hostnames (no overlay) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{{ inventory_hostname }}:{{ iroha_peer_port | int + item | int }}' ]" | ||
loop: "{{ range(0, replicas |int) | list }}" | ||
when: not custom_hostnames and not overlay_network | ||
|
||
- shell: "cat /dev/urandom | tr -cd [:xdigit:] | tr '[:upper:]' '[:lower:]' | head -c {{ 8 * replicas | int}}" | ||
register: random_hex | ||
when: not custom_hostnames and overlay_network | ||
|
||
- name: generate hostnames (overlay) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{{ container_basename }}-{{ item }}-{{ random_hex.stdout[item|int*8:(item|int+1)*8-1] }}:{{ iroha_peer_port }}' ]" | ||
loop: "{{ range(0, replicas) | list }}" | ||
when: not custom_hostnames and overlay_network | ||
|
||
- name: generate hostnames (custom_hostnames) | ||
set_fact: | ||
iroha_nodes: "{{ iroha_nodes }} + [ '{% if item.split(':') | length < 2 %}{{ item }}:{{ iroha_peer_port | int + idx }}{% else %}{{ item }}{% endif %}' ]" | ||
when: custom_hostnames and hostnames is defined | ||
loop: "{{ hostnames }}" | ||
loop_control: | ||
index_var: idx | ||
|
||
- set_fact: | ||
iroha_peers_map: "{{ iroha_peers_map | default([]) }} + [ {{ {'hostname': item, 'human_hostname': 'c_' + item | regex_replace('\\.', '_') | regex_replace(':', '_'), 'peer_port': item.split(':')[1] } }} ]" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- debug: | ||
var: iroha_peers_map | ||
|
||
- set_fact: | ||
iroha_nodes: "{{ iroha_peers_map }}" | ||
|
||
- set_fact: | ||
iroha_all_nodes: "{{ iroha_all_nodes }} + {{ hostvars[item]['iroha_nodes'] }}" | ||
loop: "{{ ansible_play_hosts }}" | ||
- name: copy custom genesis block | ||
copy: | ||
src: "{{ iroha_custom_genesis_block_path }}" | ||
dest: "{{ role_path }}/files/genesis.block" | ||
run_once: yes | ||
when: iroha_custom_genesis_block | ||
failed_when: iroha_custom_genesis_block_path is not defined | ||
|
||
- name: generate Iroha configs | ||
command: "./config_gen.sh -p{{ iroha_all_nodes | join(',', attribute='hostname') }} -o{{ config_local_dir }} -f" | ||
command: "./config_gen.sh -p{{ iroha_all_nodes | join(',', attribute='hostname') }} -o{{ iroha_config_local_dir }} -f" | ||
run_once: yes | ||
args: | ||
chdir: "{{ role_path }}/files" | ||
|
||
- name: make config dirs | ||
file: | ||
path: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
path: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
state: directory | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: move keys | ||
copy: | ||
src: "{{ config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
dest: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item[0].human_hostname }}" | ||
src: "{{ iroha_config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
dest: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item[0].human_hostname }}" | ||
loop: "{{ iroha_nodes | product(['.priv', '.pub']) | list }}" | ||
|
||
- name: move genesis.block | ||
copy: | ||
src: "{{ config_local_dir }}/genesis.block" | ||
dest: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
src: "{{ iroha_config_local_dir }}/genesis.block" | ||
dest: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/{{ item.human_hostname }}" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: cleanup | ||
file: | ||
path: "{{ config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
path: "{{ iroha_config_local_dir }}/{{ item[0].hostname }}{{ item[1] }}" | ||
state: absent | ||
loop: "{{ iroha_nodes | product(['.priv', '.pub']) | list }}" | ||
|
||
- name: cleanup | ||
file: | ||
path: "{{ config_local_dir }}/genesis.block" | ||
path: "{{ iroha_config_local_dir }}/genesis.block" | ||
state: absent | ||
run_once: yes | ||
become: no | ||
delegate_to: localhost | ||
when: iroha_generate_init_configs | ||
tags: ["iroha-config-gen"] | ||
|
||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ iroha_deploy_dir }}/conf" | ||
tags: ["iroha-config-gen"] | ||
|
||
- name: copy config files | ||
synchronize: | ||
src: "{{ iroha_config_local_dir }}/{{ inventory_hostname }}/conf/" | ||
dest: "{{ iroha_deploy_dir }}/conf/" | ||
recursive: yes | ||
checksum: yes | ||
when: iroha_generate_init_configs | ||
tags: ["iroha-config-gen"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,37 @@ | ||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ deploy_dir }}/conf" | ||
|
||
- stat: | ||
path: "{{ deploy_dir }}/docker-compose.yml" | ||
register: docker_compose_file | ||
|
||
- name: stop Iroha | ||
docker_service: | ||
project_src: "{{ deploy_dir }}" | ||
project_name: ansible_iroha | ||
remove_volumes: yes | ||
state: absent | ||
when: docker_compose_file.stat.exists | ||
|
||
- name: remove Iroha network (overlay) | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
driver: overlay | ||
state: absent | ||
run_once: yes | ||
when: docker_compose_file.stat.exists and overlay_network | ||
|
||
- name: remove Iroha network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
state: absent | ||
when: docker_compose_file.stat.exists and not overlay_network | ||
|
||
- name: generate Docker compose | ||
template: | ||
src: docker-compose.yml.j2 | ||
dest: "{{ deploy_dir }}/docker-compose.yml" | ||
|
||
- name: copy config files | ||
synchronize: | ||
src: "{{ config_local_dir }}/{{ inventory_hostname }}/conf/" | ||
dest: "{{ deploy_dir }}/conf/" | ||
recursive: yes | ||
delete: yes | ||
|
||
- name: generate config files | ||
template: | ||
src: config.docker.j2 | ||
dest: "{{ deploy_dir }}/conf/{{ item.human_hostname }}/config.docker" | ||
loop: "{{ iroha_nodes }}" | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
driver: overlay | ||
run_once: yes | ||
when: overlay_network | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
when: not overlay_network | ||
|
||
- name: pull Iroha | ||
command: docker-compose pull | ||
args: | ||
chdir: "{{ deploy_dir }}" | ||
changed_when: False | ||
|
||
- name: run Iroha | ||
docker_service: | ||
project_src: "{{ deploy_dir }}" | ||
project_name: ansible_iroha | ||
- block: | ||
- name: create deploy dir | ||
file: | ||
state: directory | ||
path: "{{ iroha_deploy_dir }}/conf" | ||
|
||
# Attachable overlay network cannot be created with a `docker_network` module | ||
- name: create Docker network | ||
shell: "docker network create -d overlay --attachable {{ iroha_network_name }} || true" | ||
when: iroha_overlay_network | ||
run_once: yes | ||
|
||
- name: create Docker network | ||
docker_network: | ||
name: "{{ iroha_network_name }}" | ||
when: not iroha_overlay_network | ||
|
||
- name: generate Docker Compose | ||
template: | ||
src: docker-compose.yml.j2 | ||
dest: "{{ iroha_deploy_dir }}/docker-compose.yml" | ||
notify: restart Iroha | ||
tags: ["iroha-deploy"] | ||
|
||
- name: generate config files | ||
template: | ||
src: config.docker.j2 | ||
dest: "{{ iroha_deploy_dir }}/conf/{{ item.human_hostname }}/config.docker" | ||
notify: restart Iroha | ||
loop: "{{ iroha_nodes }}" | ||
tags: ["iroha-deploy"] | ||
|
||
- name: run Iroha | ||
docker_service: | ||
project_src: "{{ iroha_deploy_dir }}" | ||
tags: ["iroha-deploy"] | ||
when: iroha_update_runtime_configs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should "Another method does not involve..." be a third method with a separate paragraph? Otherwise it seems a bit misleading.