testnet-ops/l2-setup/README.md
Prathamesh Musale 23f3a4c8ed Add instructions to run Ansible playbooks on remote machines (#5)
Part of [Automate testnet nitro deployments using Ansible](https://www.notion.so/Automate-testnet-nitro-deployments-using-Ansible-0d15579430204b8daba9a8aa31e07568)

Co-authored-by: Adw8 <adwaitgharpure@gmail.com>
Reviewed-on: cerc-io/testnet-ops#5
Co-authored-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
Co-committed-by: Prathamesh Musale <prathamesh@noreply.git.vdb.to>
2024-09-09 13:37:41 +00:00

148 lines
4.2 KiB
Markdown

# l2-setup
## Setup Ansible
To get started, follow the [installation](../README.md#installation) guide to setup ansible on your machine
## Setup
The following commands have to be executed in the [`l2-setup`](./) directory:
- Copy the `l2-vars.example.yml` vars file:
```bash
cp l2-vars.example.yml l2-vars.yml
```
- Edit [`l2-vars.yml`](./l2-vars.yml) with the required values:
```yaml
# L1 chain ID
l1_chain_id: ""
# L1 RPC endpoint
l1_rpc: ""
# L1 RPC endpoint host or IP address
l1_host: ""
# L1 RPC endpoint port number
l1_port: ""
# L1 Beacon endpoint
l1_beacon: ""
# Address of the funded account on L1
# Used for optimism contracts deployment
l1_address: ""
# Private key of the funded account on L1
l1_priv_key: ""
```
## Run L2
### On Local Host
- To setup and run L2 locally, execute the `run-optimism.yml` Ansible playbook:
```bash
LANG=en_US.utf8 ansible-playbook run-optimism.yml --extra-vars='{ "target_host": "localhost"}' --user $USER -kK
```
NOTE: By default, deployments are created in an `out` directory. To change this location, update the `l2_directory` variable in the [setup-vars.yml](./setup-vars.yml) file
- For skipping container build, set `"skip_container_build" : true` in the `--extra-vars` parameter:
```bash
LANG=en_US.utf8 ansible-playbook run-optimism.yml --extra-vars='{"target_host" : "localhost", "skip_container_build": true}' --user $USER -kK
```
- To run using existing contracts deployment:
- Update `artifact_path` in [`setup-vars.yml`](./setup-vars.yml) file with path to data directory of the existing deployment
- Run the ansible playbook with `"existing_contracts_deployment": true` in the `--extra-vars` parameter:
```bash
LANG=en_US.utf8 ansible-playbook run-optimism.yml --extra-vars='{"target_host" : "localhost", "existing_contracts_deployment": true}' --user $USER -kK
```
### On Remote Host
To run the playbook on a remote host:
- Create a new `hosts.ini` file:
```bash
cp ../hosts.example.ini hosts.ini
```
- Edit the [`hosts.ini`](./hosts.ini) file to run the playbook on a remote machine:
```ini
[<deployment_host>]
<host_name> ansible_host=<target_ip> ansible_user=<ssh_user> ansible_ssh_common_args='-o ForwardAgent=yes'
```
- Replace `<deployment_host>` with `l2_host`
- Replace `<host_name>` with the alias of your choice
- Replace `<target_ip>` with the IP address or hostname of the target machine
- Replace `<ssh_user>` with the SSH username (e.g., dev, ubuntu)
- Verify that you are able to connect to the host using the following command
```bash
ansible all -m ping -i hosts.ini -k
# Expected output:
# <host_name> | SUCCESS => {
# "ansible_facts": {
# "discovered_interpreter_python": "/usr/bin/python3.10"
# },
# "changed": false,
# "ping": "pong"
# }
```
- Execute the `run-optimism.yml` Ansible playbook for remote deployment:
```bash
LANG=en_US.utf8 ansible-playbook -i hosts.ini run-optimism.yml --extra-vars='{ "target_host": "l2_host"}' --user $USER -kK
```
- For skipping container build, set `"skip_container_build" : true` in the `--extra-vars` parameter:
```bash
LANG=en_US.utf8 ansible-playbook -i hosts.ini run-optimism.yml --extra-vars='{"target_host" : "l2_host", "skip_container_build": true}' --user $USER -kK
```
- To run using existing contracts deployment:
- Update `artifact_path` in [`setup-vars.yml`](./setup-vars.yml) file with path to data directory of the existing deployment
- Run the ansible playbook with `"existing_contracts_deployment": true` in the `--extra-vars` parameter:
```bash
LANG=en_US.utf8 ansible-playbook -i hosts.ini run-optimism.yml --extra-vars='{"target_host" : "l2_host", "existing_contracts_deployment": true}' --user $USER -kK
```
## Check Deployment Status
Run the following commands in the directory where the optimism-deployment is created:
- Follow optimism contracts deployment logs:
```bash
laconic-so deployment --dir optimism-deployment logs -f fixturenet-optimism-contracts
```
- Check L2 logs:
```bash
laconic-so deployment --dir optimism-deployment logs -f op-geth
# Ensure new blocks are getting created
```