diff --git a/ansible/playbooks/deploy-nodes.yml b/ansible/playbooks/deploy-nodes.yml index 704a4a1..f89610a 100644 --- a/ansible/playbooks/deploy-nodes.yml +++ b/ansible/playbooks/deploy-nodes.yml @@ -2,6 +2,13 @@ # Deploy nodes playbook: Deploy and manage Lean nodes # Requires node_names to be specified (comma or space separated) # This playbook runs on localhost to parse node names, then deploys to remote hosts +# +# Before deployment, it syncs essential config files from local to remote: +# - validator-config.yaml +# - node key files (*.key) +# - config.yaml, validators.yaml, nodes.yaml +# - genesis.ssz, genesis.json +# - hash-sig-keys/ directory (if exists, for qlean nodes) - name: Parse and validate node names hosts: localhost @@ -82,6 +89,11 @@ groups: deployment_targets loop: "{{ deploy_nodes }}" + - name: Store local genesis dir for remote plays + set_fact: + local_genesis_dir_path: "{{ genesis_dir }}" + cacheable: yes + - name: Deploy nodes on remote hosts hosts: deployment_targets gather_facts: yes @@ -92,8 +104,85 @@ validator_config_file: "{{ genesis_dir }}/validator-config.yaml" # node_name is set to inventory_hostname (which matches the node name) node_name: "{{ inventory_hostname }}" + # Local genesis directory for syncing config files (from localhost play) + local_genesis_dir: "{{ hostvars['localhost']['local_genesis_dir_path'] }}" tasks: + - name: Create remote genesis directory + file: + path: "{{ genesis_dir }}" + state: directory + mode: '0755' + tags: + - deploy + - sync + + - name: Sync validator-config.yaml to remote host + copy: + src: "{{ local_genesis_dir }}/validator-config.yaml" + dest: "{{ genesis_dir }}/validator-config.yaml" + mode: '0644' + force: yes + tags: + - deploy + - sync + + - name: Sync node key file to remote host + copy: + src: "{{ local_genesis_dir }}/{{ node_name }}.key" + dest: "{{ genesis_dir }}/{{ node_name }}.key" + mode: '0600' + force: yes + tags: + - deploy + - sync + + - name: Sync essential genesis config files + copy: + src: "{{ local_genesis_dir }}/{{ item }}" + dest: "{{ genesis_dir }}/{{ item }}" + mode: '0644' + force: yes + loop: + - config.yaml + - validators.yaml + - nodes.yaml + - genesis.ssz + - genesis.json + tags: + - deploy + - sync + + - name: Check if hash-sig-keys directory exists locally + stat: + path: "{{ local_genesis_dir }}/hash-sig-keys" + register: hash_sig_keys_local + delegate_to: localhost + tags: + - deploy + - sync + + - name: Create hash-sig-keys directory on remote + file: + path: "{{ genesis_dir }}/hash-sig-keys" + state: directory + mode: '0755' + when: hash_sig_keys_local.stat.exists + tags: + - deploy + - sync + + - name: Sync hash-sig-keys directory (for qlean nodes) + copy: + src: "{{ local_genesis_dir }}/hash-sig-keys/" + dest: "{{ genesis_dir }}/hash-sig-keys/" + mode: '0644' + force: yes + when: hash_sig_keys_local.stat.exists + tags: + - deploy + - sync + - name: Clean node data directory raw: rm -rf {{ data_dir }}/{{ node_name }} when: diff --git a/ansible/playbooks/helpers/deploy-single-node.yml b/ansible/playbooks/helpers/deploy-single-node.yml index 116a3e5..34f17f7 100644 --- a/ansible/playbooks/helpers/deploy-single-node.yml +++ b/ansible/playbooks/helpers/deploy-single-node.yml @@ -6,20 +6,22 @@ set_fact: client_type: "{{ node_name.split('_')[0] }}" -- name: Set validator config file path +- name: Set validator config file paths set_fact: actual_validator_config_file: "{{ genesis_dir }}/validator-config.yaml" + local_validator_config_file: "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" -- name: Extract node configuration +- name: Extract node configuration (from local config) shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .name" {{ actual_validator_config_file }} + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .name" {{ local_validator_config_file }} register: node_check changed_when: false failed_when: false + delegate_to: localhost - name: Fail if node not found in config fail: - msg: "Node '{{ node_name }}' not found in {{ actual_validator_config_file }}" + msg: "Node '{{ node_name }}' not found in {{ local_validator_config_file }}" when: node_check.stdout == "" or node_check.rc != 0 - name: Set zeam validator config diff --git a/ansible/roles/ethlambda/tasks/main.yml b/ansible/roles/ethlambda/tasks/main.yml index cae6b0b..3fda6f8 100644 --- a/ansible/roles/ethlambda/tasks/main.yml +++ b/ansible/roles/ethlambda/tasks/main.yml @@ -31,9 +31,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: ethlambda_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - metricsPort diff --git a/ansible/roles/grandine/tasks/main.yml b/ansible/roles/grandine/tasks/main.yml index 3bdda8a..6c8060a 100644 --- a/ansible/roles/grandine/tasks/main.yml +++ b/ansible/roles/grandine/tasks/main.yml @@ -31,9 +31,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: grandine_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - privkey diff --git a/ansible/roles/lantern/tasks/main.yml b/ansible/roles/lantern/tasks/main.yml index 3920ad8..8f18357 100644 --- a/ansible/roles/lantern/tasks/main.yml +++ b/ansible/roles/lantern/tasks/main.yml @@ -30,9 +30,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: lantern_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - metricsPort diff --git a/ansible/roles/lighthouse/tasks/main.yml b/ansible/roles/lighthouse/tasks/main.yml index b00af77..7385715 100644 --- a/ansible/roles/lighthouse/tasks/main.yml +++ b/ansible/roles/lighthouse/tasks/main.yml @@ -30,9 +30,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: lighthouse_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - metricsPort diff --git a/ansible/roles/qlean/tasks/main.yml b/ansible/roles/qlean/tasks/main.yml index 69187cb..07579b7 100644 --- a/ansible/roles/qlean/tasks/main.yml +++ b/ansible/roles/qlean/tasks/main.yml @@ -30,9 +30,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: qlean_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - metricsPort @@ -48,10 +49,11 @@ - name: Extract validator index from validators.yaml shell: | - yq eval '."{{ node_name }}" | .[0]' "{{ genesis_dir }}/validators.yaml" + yq eval '."{{ node_name }}" | .[0]' "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validators.yaml" register: qlean_validator_index changed_when: false failed_when: false + delegate_to: localhost - name: Set validator index set_fact: diff --git a/ansible/roles/ream/tasks/main.yml b/ansible/roles/ream/tasks/main.yml index ba8ccbd..1810958 100644 --- a/ansible/roles/ream/tasks/main.yml +++ b/ansible/roles/ream/tasks/main.yml @@ -30,9 +30,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: ream_node_config changed_when: false + delegate_to: localhost loop: - enrFields.quic - metricsPort diff --git a/ansible/roles/zeam/tasks/main.yml b/ansible/roles/zeam/tasks/main.yml index 9f28fa4..74c0473 100644 --- a/ansible/roles/zeam/tasks/main.yml +++ b/ansible/roles/zeam/tasks/main.yml @@ -38,9 +38,10 @@ - name: Extract node configuration from validator-config.yaml shell: | - yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ hostvars['localhost']['local_genesis_dir_path'] }}/validator-config.yaml" register: node_config changed_when: false + delegate_to: localhost loop: - metricsPort - privkey diff --git a/client-cmds/grandine-cmd.sh b/client-cmds/grandine-cmd.sh index b8456a6..a2f1847 100644 --- a/client-cmds/grandine-cmd.sh +++ b/client-cmds/grandine-cmd.sh @@ -10,7 +10,7 @@ node_binary="$grandine_bin \ --address 0.0.0.0 \ --hash-sig-key-dir $configDir/hash-sig-keys" -node_docker="sifrai/lean:unstable \ +node_docker="sifrai/lean:devnet-2 \ --genesis /config/config.yaml \ --validator-registry-path /config/validators.yaml \ --bootnodes /config/nodes.yaml \ diff --git a/spin-node.sh b/spin-node.sh index 8e512a6..898dae6 100755 --- a/spin-node.sh +++ b/spin-node.sh @@ -237,9 +237,14 @@ for item in "${spin_nodes[@]}"; do # create and/or cleanup datadirs itemDataDir="$dataDir/$item" mkdir -p $itemDataDir - cmd="sudo rm -rf $itemDataDir/*" - echo $cmd - eval $cmd + if [ -n "$cleanData" ]; then + cmd="rm -rf \"$itemDataDir\"/*" + if [ -n "$dockerWithSudo" ]; then + cmd="sudo $cmd" + fi + echo "$cmd" + eval "$cmd" + fi # parse validator-config.yaml for $item to load args values source parse-vc.sh