infra-role-geth/tasks/generate.yml

83 lines
2.2 KiB
YAML
Raw Normal View History

---
- name: Geth | Create keys directory
file:
path: '{{ geth_keys_path }}'
state: directory
- name: Geth | Check if account file exists
stat:
path: '{{ geth_account_json_file }}'
register: account_file
when: geth_account_json is not defined
- name: Geth | Create password file
copy:
dest: '{{ geth_account_pass_file }}'
content: '{{ geth_account_pass | mandatory }}'
owner: dockremap
group: docker
mode: 0600
- name: Geth | Write account JSON
copy:
dest: '{{ geth_account_json_file }}'
content: '{{ geth_account_json | mandatory }}'
owner: dockremap
group: docker
mode: 0640
when: >
geth_account_addr is defined and
geth_account_json is defined and
geth_account_json != ""
- name: Geth | Generate account
block:
- name: Geth | Generate account JSON
docker_container:
name: '{{ geth_cont_name }}'
image: '{{ geth_cont_image }}'
pull: true
auto_remove: yes
command: |
account new
--keystore=/keys
--password=/keys/account.pass
volumes:
- '{{ geth_cont_vol }}/keys:/keys:rw'
- name: Geth | Find newly generate account file
find:
paths: '{{ geth_keys_path }}'
patterns: 'UTC--*'
file_type: file
register: found_account_files
- name: Geth | Rename generated account file
command: 'mv {{ found_account_files.files[0].path }} {{ geth_account_json_file }}'
- name: Geth | Save account address
slurp:
src: '{{ geth_account_json_file }}'
register: geth_account
- name: Geth | Extract account address
set_fact:
geth_account_addr: '{{ (geth_account.content | b64decode | from_json)["address"] }}'
when: >
geth_account_json is not defined and
geth_account_addr is not defined and
account_file.stat.exists == False
- name: Geth | Verify account data is available
assert:
that:
- geth_account_json is defined
- geth_account_addr is defined
- name: Geth | Save account address to file
copy:
dest: '{{ geth_account_addr_file }}'
content: '{{ geth_account_addr | mandatory }}'
owner: dockremap
group: docker