diff --git a/ansible-devnet/genesis/validator-config.yaml b/ansible-devnet/genesis/validator-config.yaml index e98ac3b..e8011f3 100644 --- a/ansible-devnet/genesis/validator-config.yaml +++ b/ansible-devnet/genesis/validator-config.yaml @@ -47,4 +47,15 @@ validators: ip: "46.224.135.177" quic: 9001 metricsPort: 8081 - count: 1 \ No newline at end of file + count: 1 + + - name: "lighthouse_0" + # node id a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2 + # peer id 16Uiu2HAm7TYVs6qvDKnrovd9m4vvRikc4HPXm1WyLumKSe5fHxBv + privkey: "4fd22cf461fbeae4947a3fdaef8d533fc7fd1ef1ce4cd98e993210c18234df3f" + # verify /ip4/127.0.0.1/udp/9004/quic-v1/p2p/16Uiu2HAm7TYVs6qvDKnrovd9m4vvRikc4HPXm1WyLumKSe5fHxBv + enrFields: + ip: "46.224.135.169" + quic: 9001 + metricsPort: 8081 + count: 1 diff --git a/ansible/roles/lighthouse/defaults/main.yml b/ansible/roles/lighthouse/defaults/main.yml new file mode 100644 index 0000000..9fdfbe7 --- /dev/null +++ b/ansible/roles/lighthouse/defaults/main.yml @@ -0,0 +1,7 @@ +--- +# Default variables for lighthouse role +# Note: These are fallback defaults. Actual values are extracted from client-cmds/ream-cmd.sh +# in the tasks/main.yml file. These defaults are used if extraction fails. + +lighthouse_docker_image: "hopinheimer/lighthouse:latest" +deployment_mode: docker diff --git a/ansible/roles/lighthouse/tasks/main.yml b/ansible/roles/lighthouse/tasks/main.yml new file mode 100644 index 0000000..feed56c --- /dev/null +++ b/ansible/roles/lighthouse/tasks/main.yml @@ -0,0 +1,106 @@ +--- +# Lighthouse role: Deploy and manage Lighthouse nodes +# Converts client-cmds/lighthouse-cmd.sh logic to Ansible tasks + +- name: Extract docker image from client-cmd.sh + shell: | + # Extract the first word (docker image) from node_docker line + # playbook_dir points to ansible/playbooks, go up two levels to reach project root + project_root="$(cd '{{ playbook_dir }}/../..' && pwd)" + grep -E '^node_docker=' "$project_root/client-cmds/lighthouse-cmd.sh" | head -1 | sed -E 's/.*node_docker="([^ "]+).*/\1/' + register: lighthouse_docker_image_raw + changed_when: false + delegate_to: localhost + run_once: true + +- name: Extract deployment mode from client-cmd.sh + shell: | + # Extract the value from node_setup line + project_root="$(cd '{{ playbook_dir }}/../..' && pwd)" + grep -E '^node_setup=' "$project_root/client-cmds/lighthouse-cmd.sh" | head -1 | sed -E 's/.*node_setup="([^"]+)".*/\1/' + register: lighthouse_deployment_mode_raw + changed_when: false + delegate_to: localhost + run_once: true + +- name: Set docker image and deployment mode from client-cmd.sh + set_fact: + lighthouse_docker_image: "{{ lighthouse_docker_image_raw.stdout | trim | default('hopinheimer/lighthouse:latest') }}" + deployment_mode: "{{ lighthouse_deployment_mode_raw.stdout | trim | default('docker') }}" + +- name: Extract node configuration from validator-config.yaml + shell: | + yq eval ".validators[] | select(.name == \"{{ node_name }}\") | .{{ item }}" "{{ genesis_dir }}/validator-config.yaml" + register: lighthouse_node_config + changed_when: false + loop: + - enrFields.quic + - privkey + when: node_name is defined + +- name: Set node ports + set_fact: + lighthouse_quic_port: "{{ lighthouse_node_config.results[0].stdout }}" + lighthouse_privkey: "{{ lighthouse_node_config.results[1].stdout }}" + when: lighthouse_node_config is defined + +- name: Ensure node key file exists + stat: + path: "{{ genesis_dir }}/{{ node_name }}.key" + register: node_key_stat + +- name: Debug node key file check + debug: + msg: "Checking for key file at {{ genesis_dir }}/{{ node_name }}.key - exists: {{ node_key_stat.stat.exists | default('undefined') }}" + +- name: Fail if node key file is missing + fail: + msg: "Node key file {{ node_name }}.key not found in {{ genesis_dir }}" + when: not (node_key_stat.stat.exists | default(false)) + +- name: Clean node data directory + file: + path: "{{ data_dir }}/{{ node_name }}" + state: absent + when: clean_data | default(false) | bool + +- name: Create node data directory + file: + path: "{{ data_dir }}/{{ node_name }}" + state: directory + mode: '0755' + +- name: Deploy Lighthouse node using Docker + block: + - name: Pull Lighthouse docker image + command: docker pull {{ lighthouse_docker_image }} + register: lighthouse_docker_pull + changed_when: '"Downloaded newer image" in lighthouse_docker_pull.stdout' + + - name: Stop existing Lighthouse container (if any) + command: docker rm -f {{ node_name }} + register: lighthouse_stop + failed_when: false + changed_when: lighthouse_stop.rc == 0 + + - name: Start Lighthouse container + command: >- + docker run -d + --name {{ node_name }} + --restart unless-stopped + --network host + -v {{ genesis_dir }}:/config:ro + -v {{ data_dir }}/{{ node_name }}:/data + {{ lighthouse_docker_image }} + lighthouse lean_node + --datadir /data + --config /config/config.yaml + --validators /config/validator-config.yaml + --nodes /config/nodes.yaml + --node-id {{ node_name }} + --private-key /config/{{ node_name }}.key + --genesis-json /config/genesis.json + --socket-port {{ lighthouse_quic_port }} + register: lighthouse_container + changed_when: lighthouse_container.rc == 0 + when: deployment_mode == 'docker' diff --git a/client-cmds/lighthouse-cmd.sh b/client-cmds/lighthouse-cmd.sh new file mode 100644 index 0000000..3675d73 --- /dev/null +++ b/client-cmds/lighthouse-cmd.sh @@ -0,0 +1,22 @@ +#!/bin/bash +node_binary="$lighthouse_bin lean_node \ + --datadir \"$dataDir/$item\" \ + --config \"$configDir/config.yaml\" \ + --validators \"$configDir/validator-config.yaml\" \ + --nodes \"$configDir/nodes.yaml\" \ + --node-id \"$item\" \ + --private-key \"$configDir/$privKeyPath\" \ + --genesis-json \"$configDir/genesis.json\" \ + --socket-port $quicPort" + +node_docker="hopinheimer/lighthouse:latest lighthouse lean_node \ + --datadir /data \ + --config /config/config.yaml \ + --validators /config/validator-config.yaml \ + --nodes /config/nodes.yaml \ + --node-id $item \ + --private-key /config/$privKeyPath \ + --genesis-json /config/genesis.json \ + --socket-port $quicPort" + +node_setup="docker" diff --git a/generate-ansible-inventory.sh b/generate-ansible-inventory.sh index e980564..b15feb2 100755 --- a/generate-ansible-inventory.sh +++ b/generate-ansible-inventory.sh @@ -54,6 +54,8 @@ all: hosts: {} lantern_nodes: hosts: {} + lighthouse_nodes: + hosts: {} EOF # Extract node information from validator-config.yaml @@ -61,7 +63,7 @@ nodes=($(yq eval '.validators[].name' "$VALIDATOR_CONFIG")) # Process each node and generate inventory entries for node_name in "${nodes[@]}"; do - # Extract client type (zeam, ream, qlean, lantern) + # Extract client type (zeam, ream, qlean, lantern, lighthouse) IFS='_' read -r -a elements <<< "$node_name" client_type="${elements[0]}" group_name="${client_type}_nodes" diff --git a/local-devnet/genesis/validator-config.yaml b/local-devnet/genesis/validator-config.yaml index 3aec08b..d41cce7 100644 --- a/local-devnet/genesis/validator-config.yaml +++ b/local-devnet/genesis/validator-config.yaml @@ -47,4 +47,15 @@ validators: ip: "127.0.0.1" quic: 9004 metricsPort: 8084 - count: 1 \ No newline at end of file + count: 1 + + - name: "lighthouse_0" + # node id a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2 + # peer id 16Uiu2HAm7TYVs6qvDKnrovd9m4vvRikc4HPXm1WyLumKSe5fHxBv + privkey: "4fd22cf461fbeae4947a3fdaef8d533fc7fd1ef1ce4cd98e993210c18234df3f" + # verify /ip4/127.0.0.1/udp/9004/quic-v1/p2p/16Uiu2HAm7TYVs6qvDKnrovd9m4vvRikc4HPXm1WyLumKSe5fHxBv + enrFields: + ip: "127.0.0.1" + quic: 9005 + metricsPort: 8085 + count: 1 diff --git a/run-ansible.sh b/run-ansible.sh index ed16ec6..cf7e91a 100755 --- a/run-ansible.sh +++ b/run-ansible.sh @@ -57,8 +57,8 @@ fi # Update inventory with SSH key file and user if provided if command -v yq &> /dev/null; then - # Get all remote host groups (zeam_nodes, ream_nodes, qlean_nodes, lantern_nodes) - for group in zeam_nodes ream_nodes qlean_nodes lantern_nodes; do + # Get all remote host groups (zeam_nodes, ream_nodes, qlean_nodes, lantern_nodes, lighthouse_nodes) + for group in zeam_nodes ream_nodes qlean_nodes lantern_nodes lighthouse_nodes; do # Get all hosts in this group hosts=$(yq eval ".all.children.$group.hosts | keys | .[]" "$INVENTORY_FILE" 2>/dev/null || echo "") for host in $hosts; do