chain-spec-configuration.yml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. - name: Configure chain spec and start joystream-node service on the servers
  2. hosts: all
  3. vars:
  4. local_dir: ~/Joystream/joystream
  5. # Generates random number between 1000..9999
  6. random_suffix: "{{ 10000 | random(1000) }}"
  7. data_path: ./data
  8. change_spec_path: "{{ data_path }}/chainspec.json"
  9. remote_code_path: "/home/ubuntu/joystream"
  10. remote_chain_spec_path: "{{ remote_code_path }}/chainspec.json"
  11. tasks:
  12. - name: Run subkey to generate node keys
  13. local_action: ansible.builtin.command {{ local_dir }}/target/release/chain-spec-builder generate -a 2 --chain-spec-path {{ change_spec_path }} --deployment live --endowed 1 --keystore-path {{ data_path }}
  14. register: chain_spec_output
  15. run_once: true
  16. - name: Run subkey to generate node keys
  17. local_action: ansible.builtin.command subkey generate-node-key
  18. register: subkey_output
  19. - name: Print to stdout
  20. debug:
  21. msg:
  22. - "Public Key: {{ subkey_output.stderr }}"
  23. - "Private Key: {{ subkey_output.stdout }}"
  24. - name: Print to stdout chain spec
  25. debug: var=chain_spec_output.stdout
  26. run_once: true
  27. - name: Save output of chain spec to local file
  28. local_action: copy content={{ chain_spec_output.stdout }} dest="{{ data_path }}/chain_spec_output.txt"
  29. - name: Change chain spec name, id, protocolId
  30. delegate_to: localhost
  31. json_modify:
  32. change_spec_path: "{{ change_spec_path }}"
  33. prefix: "{{ random_suffix }}"
  34. all_nodes: "{{ hostvars }}"
  35. register: result
  36. run_once: true
  37. - name: Print output of modified chainspec
  38. debug:
  39. var: result.result
  40. - name: Copying chain spec file to server
  41. copy:
  42. src: "{{ change_spec_path }}"
  43. dest: "{{ remote_chain_spec_path }}"
  44. - set_fact:
  45. chain_path: "{{ remote_code_path }}/chains/{{ result.result.id }}"
  46. - set_fact:
  47. network_path: "{{ chain_path }}/network"
  48. keystore_path: "{{ chain_path }}/keystore/"
  49. - set_fact:
  50. secret_path: "{{ network_path }}/secret"
  51. - name: Creating chains directory
  52. file:
  53. path: "{{ item }}"
  54. state: directory
  55. loop:
  56. - "{{ network_path }}"
  57. - name: Copy secret to remote host
  58. copy:
  59. dest: "{{ secret_path }}"
  60. content: "{{ subkey_output.stdout }}"
  61. - name: Copy auth directory to remote host
  62. copy:
  63. src: "{{ data_path }}/auth-{{ ansible_play_batch.index(inventory_hostname) }}/"
  64. dest: "{{ keystore_path }}"
  65. - name: Create a service file
  66. template:
  67. src: joystream-node.service.j2
  68. dest: /etc/systemd/system/joystream-node.service
  69. vars:
  70. keystore_path: "{{ keystore_path }}"
  71. secret_path: "{{ secret_path }}"
  72. keystore_path: "{{ remote_chain_spec_path }}"
  73. become: yes
  74. - name: Start service joystream-node, if not started
  75. service:
  76. name: joystream-node
  77. state: started
  78. become: yes