forked from cerc-io/testnet-ops
Prathamesh Musale
a7af33a45b
Part of [Automate testnet nitro deployments using Ansible](https://www.notion.so/Automate-testnet-nitro-deployments-using-Ansible-0d15579430204b8daba9a8aa31e07568) - Add playbooks to setup and run L1 and L2 nitro nodes Co-authored-by: Adw8 <adwaitgharpure@gmail.com> Reviewed-on: cerc-io/testnet-ops#2 Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to> Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
106 lines
3.8 KiB
YAML
106 lines
3.8 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: 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
|
|
command: laconic-so fetch-stack git.vdb.to/cerc-io/nitro-stack --git-ssh --pull
|
|
ignore_errors: yes
|
|
|
|
- name: Clone repositories required for nitro-stack
|
|
command: laconic-so --stack ~/cerc/nitro-stack/stack-orchestrator/stacks/nitro-node setup-repositories --git-ssh --pull
|
|
ignore_errors: yes
|
|
|
|
- name: Build containers
|
|
command: laconic-so --stack ~/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 }}"
|