Skip to content
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pipx inject ansible-core requests pynetbox pyutils pytz netaddr

```bash
pipx install ansible-lint

```

```bash
Expand Down
1 change: 1 addition & 0 deletions depin/core/roles/metrics/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ metrics_port:
autonomi: 33002
hychain: 33003
storagechain: 33004
avalanche: 33006
36 changes: 36 additions & 0 deletions depin/services/roles/avalanche/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# defaults/main.yml

# Command to execute (install, uninstall, etc.)
avalanche_cmd: "{{ depin_cmd | default('install') }}"

# AvalancheGo version to install
avalanche_version: "1.11.11"

# Determine the architecture (amd64 or arm64)
avalanche_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'amd64' }}"

# Download URL for AvalancheGo binary
avalanche_download_url: "https://github.com/ava-labs/avalanchego/releases/download/v{{ avalanche_version }}/avalanchego-linux-{{ avalanche_arch }}-v{{ avalanche_version }}.tar.gz"

# Installation directory for AvalancheGo
avalanche_install_dir: '/opt/avalanche/{{ avalanche_version }}'

# Configuration directory for AvalancheGo
avalanche_config_dir: '/home/{{ ansible_user_id }}/.avalanchego' # Or another appropriate path

# User and group to run AvalancheGo service
avalanche_user: '{{ ansible_user_id }}'
avalanche_group: '{{ ansible_user_id }}'

# Network ID ('mainnet' or 'fuji' for testnet)
avalanche_network_id: 'mainnet'

# Additional necessary variables
avalanche_ip_mode: 'dynamic' # 'dynamic' or 'static'
avalanche_public_ip: '' # Automatically determined if empty and ip_mode == 'static'
avalanche_rpc_public: false # true or false
avalanche_admin_api_enabled: false # true or false
avalanche_index_enabled: false # true or false
avalanche_state_sync_enabled: true # true or false
avalanche_archival_mode: false # true or false
avalanche_db_dir: '' # Path to database directory if needed
209 changes: 209 additions & 0 deletions depin/services/roles/avalanche/tasks/commands/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
# tasks/commands/install.yml

---

- name: Determine OS family
set_fact:
os_family: "{{ ansible_facts['os_family'] }}"

- name: Install required packages for AvalancheGo (Debian)
become: true
ansible.builtin.package:
name:
- curl
- wget
- dnsutils
state: present
when: os_family == 'Debian'

- name: Install required packages for AvalancheGo (RedHat)
become: true
ansible.builtin.package:
name:
- curl
- wget
- bind-utils
- policycoreutils-python-utils
- policycoreutils
state: present
when: os_family == 'RedHat'

- name: Set avalanche architecture
set_fact:
avalanche_arch: "{{ 'arm64' if ansible_facts['architecture'] == 'aarch64' else 'amd64' }}"

- name: Set download URL for AvalancheGo
set_fact:
avalanche_download_url: "https://github.com/ava-labs/avalanchego/releases/download/v{{ avalanche_version }}/avalanchego-linux-{{ avalanche_arch }}-v{{ avalanche_version }}.tar.gz"

- name: Get public IP address
ansible.builtin.uri:
url: https://api.ipify.org
return_content: yes
register: public_ip
when:
- avalanche_public_ip == ''
- avalanche_ip_mode == 'static'

- name: Set public IP address fact
set_fact:
avalanche_public_ip: "{{ public_ip.content | trim }}"
when:
- avalanche_public_ip == ''
- avalanche_ip_mode == 'static'

- name: Create program folder
become: true
ansible.builtin.file:
state: directory
owner: root
group: root
mode: '0755'
dest: "{{ avalanche_install_dir }}"

- name: Verify that the program folder was created
ansible.builtin.stat:
path: "{{ avalanche_install_dir }}"
register: avalanche_program_folder

- name: Assert that the program folder exists
ansible.builtin.assert:
that:
- avalanche_program_folder.stat.exists
- avalanche_program_folder.stat.isdir

- name: Download AvalancheGo
become: true
ansible.builtin.get_url:
url: "{{ avalanche_download_url }}"
dest: /tmp/avalanchego.tar.gz
mode: '0644'
register: download_result
retries: 3
delay: 10
until: download_result is succeeded

- name: Fail if AvalancheGo download failed
ansible.builtin.fail:
msg: "Failed to download AvalancheGo from {{ avalanche_download_url }}"
when: download_result is failed

- name: Extract AvalancheGo
become: true
ansible.builtin.unarchive:
src: /tmp/avalanchego.tar.gz
dest: "{{ avalanche_install_dir }}"
remote_src: yes
extra_opts:
- --strip-components=1

- name: Ensure avalanchego binary is executable
become: true
ansible.builtin.file:
path: "{{ avalanche_install_dir }}/avalanchego"
mode: '0755'

- name: Verify that the AvalancheGo binary exists
ansible.builtin.stat:
path: "{{ avalanche_install_dir }}/avalanchego"
register: avalanchego_binary

- name: Assert that the AvalancheGo binary exists
ansible.builtin.assert:
that:
- avalanchego_binary.stat.exists
- (avalanchego_binary.stat.mode | int == 755) or (avalanchego_binary.stat.mode | int == 493)

- name: Adjust SELinux context for avalanchego binary
become: true
ansible.builtin.command: "semanage fcontext -a -t bin_t '{{ avalanche_install_dir }}/avalanchego' || semanage fcontext -m -t bin_t '{{ avalanche_install_dir }}/avalanchego'"
args:
warn: false
when: ansible_facts['os_family'] == 'RedHat'

- name: Restore SELinux context
become: true
ansible.builtin.command: "restorecon -Fv '{{ avalanche_install_dir }}/avalanchego'"
when: ansible_facts['os_family'] == 'RedHat'

- name: Symlink avalanchego binary
become: true
ansible.builtin.file:
src: "{{ avalanche_install_dir }}/avalanchego"
dest: /usr/local/bin/avalanchego
state: link
force: true

- name: Verify symlink for AvalancheGo binary
ansible.builtin.stat:
path: /usr/local/bin/avalanchego
follow: false
register: avalanchego_symlink

- name: Assert that the symlink exists and is correct
ansible.builtin.assert:
that:
- avalanchego_symlink.stat.islnk
- avalanchego_symlink.stat.lnk_source == "{{ avalanche_install_dir }}/avalanchego"

- name: Create configuration directories
become: true
ansible.builtin.file:
path: "{{ item }}"
state: directory
owner: "{{ avalanche_user }}"
group: "{{ avalanche_group }}"
mode: '0755'
loop:
- "{{ avalanche_config_dir }}/configs"
- "{{ avalanche_config_dir }}/configs/chains/C"

- name: Deploy node.json configuration
become: true
ansible.builtin.template:
src: node.json.j2
dest: "{{ avalanche_config_dir }}/configs/node.json"
mode: '0644'
owner: "{{ avalanche_user }}"
group: "{{ avalanche_group }}"

- name: Deploy config.json configuration
become: true
ansible.builtin.template:
src: config.json.j2
dest: "{{ avalanche_config_dir }}/configs/chains/C/config.json"
mode: '0644'
owner: "{{ avalanche_user }}"
group: "{{ avalanche_group }}"

- name: Create systemd service
become: true
ansible.builtin.template:
src: templates/systemd.service.j2
dest: /etc/systemd/system/avalanchego.service
mode: '0644'

- name: Verify that the AvalancheGo service file exists
ansible.builtin.stat:
path: /etc/systemd/system/avalanchego.service
register: avalanchego_service_file

- name: Assert that the AvalancheGo service file exists
ansible.builtin.assert:
that:
- avalanchego_service_file.stat.exists

- name: Reload systemd daemon
become: true
ansible.builtin.systemd:
daemon_reload: yes

- name: Start Avalanche node
ansible.builtin.include_tasks:
file: commands/start.yml

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relative path in include_tasks needs to be adjusted to ../metrics.yml since the task is being included from within the commands/ subdirectory. The current path tasks/metrics.yml will fail to locate the metrics file.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

- name: Install metrics
vars:
depin_cmd: install
ansible.builtin.include_tasks:
file: tasks/metrics.yml
9 changes: 9 additions & 0 deletions depin/services/roles/avalanche/tasks/commands/reset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Uninstall node
ansible.builtin.include_tasks:
file: commands/uninstall.yml

- name: Install node
ansible.builtin.include_tasks:
file: commands/install.yml
44 changes: 44 additions & 0 deletions depin/services/roles/avalanche/tasks/commands/restart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---

- name: Get current service info
become: true
ansible.builtin.systemd:
name: "avalanchego"
register: _avalanchego_before

- name: Set current PID
ansible.builtin.set_fact:
_avalanche_pid: "{{ _avalanchego_before['status']['ExecMainPID'] }}"

- name: Restart node
become: true
ansible.builtin.service:
name: avalanchego.service
state: restarted

- name: Assert
when: "'molecule' in groups"
block:
- name: Get new service info
become: true
ansible.builtin.systemd:
name: "avalanchego"
register: _avalanchego_after

- name: Debug new service status
debug:
msg:
- "Old PID: {{ _avalanche_pid }}"
- "New PID: {{ _avalanchego_after['status']['ExecMainPID'] }}"
- "Active State: {{ _avalanchego_after['status']['ActiveState'] }}"

- name: Check service
ansible.builtin.assert:
that:
- _avalanchego_after['status']['ActiveState'] == 'active'
- _avalanche_pid | int != _avalanchego_after['status']['ExecMainPID'] | int
quiet: true

- name: Update PID
ansible.builtin.set_fact:
_avalanche_pid: "{{ _avalanchego_after['status']['ExecMainPID'] }}"
10 changes: 10 additions & 0 deletions depin/services/roles/avalanche/tasks/commands/start.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# tasks/commands/start.yml

---
- name: Start Avalanche node
become: true
ansible.builtin.service:
name: avalanchego.service
enabled: true
daemon_reload: true
state: started
28 changes: 28 additions & 0 deletions depin/services/roles/avalanche/tasks/commands/stop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
## stop service

- name: Stop node
become: true
ansible.builtin.service:
name: avalanchego.service
enabled: false
state: stopped

- name: Assert
when: "'molecule' in groups"
block:
- name: Get service info
become: true
ansible.builtin.systemd:
name: "avalanchego"
register: _avalanchego

- name: Debug service status
debug:
var: _avalanchego.status

- name: Check service
ansible.builtin.assert:
that:
- _avalanchego['status']['ActiveState'] == 'inactive'
quiet: true
Loading