diff --git a/ansible/install.yml b/ansible/install.yml index cf4f285d8..8dc1f8787 100644 --- a/ansible/install.yml +++ b/ansible/install.yml @@ -5,6 +5,8 @@ - hosts: "{{ lookup('env','TF_VAR_TESTNET_NAME') }}:tag_Environment_{{ lookup('env','TF_VAR_TESTNET_NAME') }}" roles: - install + - {role: generic-service-prepare, when: service == 'tendermint'} - {role: config, testnet_name: "{{lookup('env','TF_VAR_TESTNET_NAME')}}"} + - {role: generic-service-config, when: service == 'tendermint'} - start diff --git a/ansible/roles/config/templates/config.toml.j2 b/ansible/roles/config/templates/config.toml.j2 index 9fd91eb6f..fd344519f 100644 --- a/ansible/roles/config/templates/config.toml.j2 +++ b/ansible/roles/config/templates/config.toml.j2 @@ -13,7 +13,7 @@ laddr = "tcp://0.0.0.0:46657" [p2p] laddr = "tcp://0.0.0.0:46656" {% if validators == true %} -{% set comma = joiner(",") %}seeds = "{% for host in groups[testnet_name]|difference(inventory_hostname) %}{{ comma() }}{{hostvars[host]["inventory_hostname"]}}:46656{% endfor %}" +{% set comma = joiner(",") %}seeds = "{% for host in ((groups[testnet_name]|default([]))+(groups['tag_Environment_'~testnet_name]|default([])))|difference(inventory_hostname) %}{{ comma() }}{{hostvars[host]["inventory_hostname"]}}:46656{% endfor %}" {% else %} seeds = "{{ seeds | default() }}" {% endif %} diff --git a/ansible/roles/config/templates/genesis-server.json.j2 b/ansible/roles/config/templates/genesis-server.json.j2 index 944d64304..0ac6dfd50 100644 --- a/ansible/roles/config/templates/genesis-server.json.j2 +++ b/ansible/roles/config/templates/genesis-server.json.j2 @@ -5,7 +5,7 @@ [ {% if validators == true %} {% set comma = joiner(",") %} -{% for host in groups[testnet_name] %} +{% for host in (groups[testnet_name]|default([]))+(groups['tag_Environment_'~testnet_name]|default([])) %} {{ comma() }} { "pub_key": { diff --git a/ansible/roles/generic-service-config/tasks/main.yml b/ansible/roles/generic-service-config/tasks/main.yml new file mode 100644 index 000000000..3eca682e1 --- /dev/null +++ b/ansible/roles/generic-service-config/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- name: here + file: "path=/etc/{{service}}/tendermint state=absent" +- name: Create tendermint directory + file: "path=/etc/{{service}}/tendermint state=directory mode=0755 owner={{service}} group={{service}}" + +- name: Initialize tendermint + command: "/usr/bin/tendermint init --home /etc/{{service}}/tendermint" + become: yes + become_user: "{{service}}" + diff --git a/ansible/roles/generic-service-prepare/tasks/main.yml b/ansible/roles/generic-service-prepare/tasks/main.yml new file mode 100644 index 000000000..0730d6a0d --- /dev/null +++ b/ansible/roles/generic-service-prepare/tasks/main.yml @@ -0,0 +1,17 @@ +--- + +- name: Create service group + group: "name={{service}}" + +- name: Create service user + user: "name={{service}} group={{service}} home=/etc/{{service}}" + +- name: Change user folder to more permissive + file: "path=/etc/{{service}} mode=0755" + +- name: Create tendermint service + template: "src=systemd.service.j2 dest=/etc/systemd/system/{{service}}.service" + +- name: Reload systemd services + systemd: "name={{service}} daemon_reload=yes enabled=no" + diff --git a/ansible/roles/generic-service-prepare/templates/systemd.service.j2 b/ansible/roles/generic-service-prepare/templates/systemd.service.j2 new file mode 100644 index 000000000..201b7942d --- /dev/null +++ b/ansible/roles/generic-service-prepare/templates/systemd.service.j2 @@ -0,0 +1,18 @@ +[Unit] +Description={{service}} server +Requires=network-online.target +After=network-online.target + +[Service] +Environment="TMHOME=/etc/{{service}}/tendermint" +Restart=on-failure +User={{service}} +Group={{service}} +PermissionsStartOnly=true +ExecStart=/usr/bin/tendermint node{{(service=='tendermint')|ternary(' --proxy_app=dummy','')}} +ExecReload=/bin/kill -HUP $MAINPID +KillSignal=SIGTERM + +[Install] +WantedBy=multi-user.target +