testnet-ops/nitro-nodes-setup/run-nitro-nodes.yml
nabarun 40428cdaa3 Add Ansible task to fetch nitro node config file (#8)
Part of [Automate testnet nitro deployments using Ansible](https://www.notion.so/Automate-testnet-nitro-deployments-using-Ansible-0d15579430204b8daba9a8aa31e07568)
- Added ansible tasks to:
  - Install yq
  - Download nitro node config file
- Modified playbooks to handle prompts when cloning repositories

Co-authored-by: Adw8 <adwaitgharpure@gmail.com>
Reviewed-on: #8
2024-09-17 13:55:18 +00:00

126 lines
4.6 KiB
YAML

- name: Setup and run nitro nodes
hosts: "{{ target_host }}"
vars_files:
- setup-vars.yml
- nitro-vars.yml
environment:
PATH: "{{ ansible_env.PATH }}:/home/{{ansible_user}}/bin"
tasks:
- name: Install yq
get_url:
url: https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
dest: /usr/bin/yq
mode: '0755'
become: yes
- name: Create directory for nitro-stack
file:
path: "{{ nitro_directory }}"
state: directory
- name: Change owner of nitro-directory
file:
path: "{{ nitro_directory }}"
owner: "{{ansible_user}}"
group: "{{ansible_user}}"
state: directory
recurse: yes
- name: Clone go-nitro stack repo
expect:
command: laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack --git-ssh --pull
responses:
"Are you sure you want to continue connecting \\(yes/no/\\[fingerprint\\]\\)\\?": "yes"
timeout: 300
ignore_errors: yes
- name: Clone repositories required for nitro-stack
expect:
command: laconic-so --stack {{ ansible_env.HOME }}/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node setup-repositories --git-ssh --pull
responses:
"Are you sure you want to continue connecting \\(yes/no/\\[fingerprint\\]\\)\\?": "yes"
timeout: 300
ignore_errors: yes
- name: Build containers
command: laconic-so --stack {{ ansible_env.HOME }}/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node build-containers --force-rebuild
when: not skip_container_build
- name: Generate spec file for L1 nitro node
template:
src: "./templates/specs/l1-nitro-spec.yml.j2"
dest: "{{ nitro_directory }}/l1-nitro-spec.yml"
- name: Generate spec file for L2 nitro node
template:
src: "./templates/specs/l2-nitro-spec.yml.j2"
dest: "{{ nitro_directory }}/l2-nitro-spec.yml"
- name: Check if deployment exists for L1 nitro node
stat:
path: "{{ nitro_directory }}/l1-nitro-deployment"
register: l1_deployment
- name: Create a deployment for L1 nitro node
command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file l1-nitro-spec.yml --deployment-dir l1-nitro-deployment
args:
chdir: "{{ nitro_directory }}"
when: not l1_deployment.stat.exists
- name: Check if deployment exists for L2 nitro node
stat:
path: "{{ nitro_directory }}/l2-nitro-deployment"
register: l2_deployment
- name: Create a deployment for L2 nitro node
command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node deploy create --spec-file l2-nitro-spec.yml --deployment-dir l2-nitro-deployment
args:
chdir: "{{ nitro_directory }}"
when: not l2_deployment.stat.exists
- name: Check if the config.env file is empty for L1 deployment
shell: "[ -s {{ nitro_directory }}/l1-nitro-deployment/config.env ] && echo 'File is not empty' || echo 'File is empty'"
register: file_check_result
- name: Display the result of the file check
debug:
msg: "{{ file_check_result.stdout }}"
- name: Copy config.env for L1 nitro deployment if it is empty
template:
src: "./templates/configs/l1-nitro-config.env.j2"
dest: "{{ nitro_directory }}/l1-nitro-deployment/config.env"
when: file_check_result.stdout == 'File is empty'
- name: Check if the config.env file is empty for L2 deployment
shell: "[ -s {{ nitro_directory }}/l2-nitro-deployment/config.env ] && echo 'File is not empty' || echo 'File is empty'"
register: file_check_result
- name: Display the result of the file check
debug:
msg: "{{ file_check_result.stdout }}"
- name: Copy config.env for L2 nitro deployment if it is empty
template:
src: "./templates/configs/l2-nitro-config.env.j2"
dest: "{{ nitro_directory }}/l2-nitro-deployment/config.env"
when: file_check_result.stdout == 'File is empty'
- name: Start deployment for L1 nitro node
command: laconic-so deployment --dir l1-nitro-deployment start
args:
chdir: "{{ nitro_directory }}"
- name: Start deployment for L2 nitro node
command: laconic-so deployment --dir l2-nitro-deployment start
args:
chdir: "{{ nitro_directory }}"
- name: Fetch the nitro-node-config file
get_url:
url: https://git.vdb.to/cerc-io/testnet-laconicd-stack/raw/branch/main/ops/stage2/nitro-node-config.yml
dest: "{{ nitro_directory }}"