Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of old node_config and CONFIG_ENV #605

Merged
merged 2 commits into from Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -125,7 +125,7 @@ Most playbooks require `DEPLOY_ENV` which is the deployment environment of the n

Here is a list of other optional vars that can be passed to all playbooks:

- `CONFIG_ENV` - [Vault configuration env](#vault-node-ansible-configuration), in cases when config env includes region or does not match `DEPLOY_ENV` (default: `$DEPLOY_ENV`)
- `CONFIG_KEY` - [Vault configuration env](#vault-node-ansible-configuration), in cases when config env includes region or does not match `DEPLOY_ENV` (default: `$DEPLOY_ENV`)
- `DEPLOY_CONFIG` - Specify a local file to use instead of an autogenerated config from vault. *NOTE: The file should not be located in vault output path (`/tmp/config/`) else it will be regenerated.*
- `LIMIT` - Ansible's `--limit` option (default: `tag_env_$DEPLOY_ENV:&tag_role_aenode`)
- `HOST` - Pass IP (or a comma separated list) to use specific host
Expand Down Expand Up @@ -212,7 +212,7 @@ Additional parameters:

Example for deploying by specifying config with region:
```bash
make deploy DEPLOY_ENV=uat_mon CONFIG_ENV=uat_mon@ap-southeast-1
make deploy DEPLOY_ENV=uat_mon CONFIG_KEY=uat_mon@ap-southeast-1
```

Example for deploying by specifying custom node config file:
Expand Down Expand Up @@ -257,17 +257,17 @@ The playbook does:

### Vault node ansible configuration

Node configurations are stored in YAML format by the Vault's KV store named 'secret'
under path `secret2/aenode/config/<ENV_TAG>` as field `node_config`
Playbook configurations are stored in YAML format by the Vault's KV store named 'secret'
under path `secret2/aenode/config/<ENV_TAG>` as field `ansible_vars`

`<ENV_TAG>` should be considered to be a node's "configuration" environment.
For instance 'terraform' setups certain nodes to look for `<env@region>`, e.g. `main_mon@us-west-1`.

Each AWS instance `<ENV_TAG>` is generated from the EC2 `env` tag or is fully specified by `node_config` tag.
It should point to the location of the vault's `node_config` field (path only).
If `node_config` is missing, empty or is set to the string `none` it will use the instance's `env` as fallback.
Each AWS instance `<ENV_TAG>` is generated from the EC2 `env` tag or is fully specified by `bootstrap_config` tag.
It should point to the location of the vault's `ansible_vars` field (path only).
If `bootstrap_config` is missing, empty or is set to the string `none` it will use the instance's `env` as fallback.

When there is no env config stored in the KV database (and instance have no `node_config` tag), the bootstrapper will try to use a file in `/ansible/vars/<env>.yml`.
When there is no env config stored in the KV database (and instance have no `bootstrap_config` tag), the bootstrapper will try to use a file in `/ansible/vars/<env>.yml`.

For quick debugging of KV config repository there are few tools provided by make.

Expand Down Expand Up @@ -308,7 +308,7 @@ cat `make -s vault-config-test`
ENV vars can control the defaults:
- `CONFIG_OUTPUT_DIR` - To override the output path where configs are dumped (default: `/tmp/config`)
- `VAULT_CONFIG_ROOT` - Vault root path where config envs are stored (default: `secret2/aenode/config`)
- `VAULT_CONFIG_FIELD` - Name of the field where the configuration YAML is stored (default: `node_config`)
- `VAULT_CONFIG_FIELD` - Name of the field where the configuration YAML is stored (default: `ansible_vars`)

Example:

Expand Down Expand Up @@ -422,7 +422,7 @@ docker attach infrastructure-local
./local_playbook_run.sh deploy.yml # + add required parameters
```

Certain playbooks require a `node_config` var to be provided. The most convenient way is to import a `.yml` file in the ansible env:
Certain playbooks require additional variables to be provided. The most convenient way is to import a `.yml` file in the ansible env:

```bash
./local_playbook_run.sh deploy.yml \
Expand Down
10 changes: 0 additions & 10 deletions ansible/deploy.yml
Expand Up @@ -198,16 +198,6 @@
notify: "restart aeternity daemon"
tags: [config]

- name: Update node configuration
copy:
# node_config has default just because of ansible-lint, otherwise it crashes badly
content: "{{ node_config | default({}) | to_nice_yaml }}"
dest: "{{ project_root }}/aeternity.yaml"
mode: '0600'
when: node_config is defined
notify: "restart aeternity daemon"
tags: [config, node_config]

- name: Start aeternity node
command: "{{ project_root }}/bin/aeternity start"
changed_when: false
Expand Down
9 changes: 5 additions & 4 deletions ansible/mnesia_reset_once.yml
Expand Up @@ -9,12 +9,13 @@
public_ipv4: "{{ ansible_ec2_public_ipv4|default(ansible_ssh_host)|default(ansible_host)|default(inventory_hostname) }}"
datadog_api_key: "{{ lookup('hashi_vault', 'secret=secret/datadog/deploy:api_key') }}"
datadog_app_key: "{{ lookup('hashi_vault', 'secret=secret/datadog/deploy:app_key') }}"
healthcheck_port: 3013

tasks:
- block:
- name: Get nodes status
uri:
url: "http://{{ item }}:{{ node_config.http.external.port | default('3013') }}/v2/status"
url: "http://{{ item }}:{{ healthcheck_port }}/v2/status"
register: hosts_status
loop: "{{ play_hosts }}"
delegate_to: localhost
Expand Down Expand Up @@ -63,7 +64,7 @@

- name: Get node status
uri:
url: "http://localhost:{{ node_config.http.external.port | default('3013') }}/v2/status"
url: "http://localhost:{{ healthcheck_port }}/v2/status"
register: status

- name: Reset mnesia database
Expand All @@ -77,9 +78,9 @@
state: absent
when: additional_storage is not defined or not additional_storage

- name: Delete local database ({{ node_config.chain.db_path }})
- name: Delete local database ({{ db_path }})
file:
path: "{{ node_config.chain.db_path }}"
path: "{{ db_path }}"
state: absent
when:
- additional_storage is defined
Expand Down
12 changes: 7 additions & 5 deletions ansible/mnesia_snapshot.yml
Expand Up @@ -23,12 +23,14 @@
datadog_app_key: "{{ lookup('hashi_vault', 'secret=secret/datadog/deploy:app_key') }}"
datadog_api_url: https://api.datadoghq.com/api/v1/downtime?api_key={{ datadog_api_key }}&application_key={{ datadog_app_key }}
downtime: "0"
db_path: data/
healthcheck_port: 3013

tasks:
- block:
- name: Get node status
uri:
url: "http://localhost:{{ node_config.http.external.port | default('3013') }}/v2/status"
url: "http://localhost:{{ healthcheck_port }}/v2/status"
register: status
failed_when: status.json.syncing == true

Expand Down Expand Up @@ -65,15 +67,15 @@

- name: Start archive
block:
- name: Archive Mnesia Directory ({{ project_root }}/{{ node_config.chain.db_path }})
- name: Archive Mnesia Directory ({{ project_root }}/{{ db_path }})
command:
cmd: tar -c -I zstd -f {{ snapshot_path }} -C {{ project_root }}/{{ node_config.chain.db_path }} .
cmd: tar -c -I zstd -f {{ snapshot_path }} -C {{ project_root }}/{{ db_path }} .
creates: "{{ snapshot_path }}"
when: additional_storage is not defined or not additional_storage

- name: Archive Mnesia Directory ({{ node_config.chain.db_path }})
- name: Archive Mnesia Directory ({{ db_path }})
command:
cmd: tar -c -I zstd -f {{ snapshot_path }} -C {{ node_config.chain.db_path }} .
cmd: tar -c -I zstd -f {{ snapshot_path }} -C {{ db_path }} .
creates: "{{ snapshot_path }}"
when:
- additional_storage is defined
Expand Down
12 changes: 7 additions & 5 deletions ansible/mnesia_snapshot_restore.yml
Expand Up @@ -16,6 +16,8 @@
restore_dir: "{{ additional_storage_mountpoint|default(project_root) }}"
should_restore: true
force_restore: false
db_path: data/
healthcheck_port: 3013

tasks:
- name: Check if snapshot was restored in {{ restore_dir }}/
Expand Down Expand Up @@ -89,20 +91,20 @@

- name: Delete old database
file:
path: "{{ node_config.chain.db_path }}"
path: "{{ db_path }}"
state: absent
when: should_restore

- name: Make sure database dir exists
file:
path: "{{ node_config.chain.db_path }}"
path: "{{ db_path }}"
state: directory
when: should_restore

- name: Restore Mnesia database to {{ node_config.chain.db_path }}/
- name: Restore Mnesia database to {{ db_path }}/
command:
cmd: tar -I zstd -x -f {{ snapshot_path }} -C {{ node_config.chain.db_path }}/
creates: "{{ node_config.chain.db_path }}/mnesia"
cmd: tar -I zstd -x -f {{ snapshot_path }} -C {{ db_path }}/
creates: "{{ db_path }}/mnesia"
notify: "start aeternity daemon"
when: should_restore
tags:
Expand Down
3 changes: 1 addition & 2 deletions ansible/monitoring.yml
Expand Up @@ -165,13 +165,12 @@
vars:
project_user: aeternity
public_ipv4: "{{ ansible_ec2_public_ipv4|default(ansible_ssh_host)|default(ansible_host)|default(inventory_hostname) }}"
network_id: "{{ (node_config['fork_management']|default(dict(network_id = 'unknown')))['network_id'] }}"
fail2ban_enable: true
datadog_api_key: "{{ lookup('hashi_vault', 'secret=secret/datadog/agent:api_key') }}"
datadog_default_tags:
- "lsb:{{ ansible_lsb.description }}"
- "public_ipv4:{{ public_ipv4|default('unknown') }}"
- "network_id:{{ network_id }}"
- "network_id:{{ network_id|default('unknown') }}"
datadog_agent_major_version: 6
datadog_config:
log_level: warning
Expand Down
2 changes: 1 addition & 1 deletion ansible/reset-net.yml
Expand Up @@ -96,4 +96,4 @@
- name: Run health checks
include_tasks: tasks/health_check.yml
vars:
node_config: "{{ node_vars }}"
healthcheck_port: "{{ node_vars.http.external.port }}"
6 changes: 0 additions & 6 deletions scripts/bootstrap.sh
Expand Up @@ -31,7 +31,6 @@ done

vault_addr=$(echo $AWS_TAGS | jq -r '.[] | select(.Key == "vault_addr") | .Value')
vault_role=$(echo $AWS_TAGS | jq -r '.[] | select(.Key == "vault_role") | .Value')
node_config=$(echo $AWS_TAGS | jq -r '.[] | select(.Key == "node_config") | .Value')
bootstrap_config=$(echo $AWS_TAGS | jq -r '.[] | select(.Key == "bootstrap_config") | .Value')
aerole=$(echo $AWS_TAGS | jq -r '.[] | select(.Key == "role") | .Value')

Expand Down Expand Up @@ -65,11 +64,6 @@ export VAULT_TOKEN=$(vault write -field=token auth/aws/login pkcs7=$PKCS7 role=$
###

# Override the env defaults with ones stored in $vault_config
if [[ -n "${node_config}" && "${node_config}" != "none" ]]; then
vault read -field=node_config ${node_config} > /tmp/node_config.yml
ANSIBLE_VARS="@/tmp/node_config.yml"
fi

if [[ -n "${bootstrap_config}" && "${bootstrap_config}" != "none" ]]; then
vault kv get -field=ansible_vars ${bootstrap_config} > /tmp/ansible_vars.yml
ANSIBLE_VARS="@/tmp/ansible_vars.yml"
Expand Down
12 changes: 6 additions & 6 deletions scripts/deploy.sh
Expand Up @@ -33,31 +33,31 @@ read -p "Deploy UAT monitoring nodes? (y/N):" uatmonchoice
if [[ $uatmonchoice == "y" ]]; then
make vault-config-update-uat_mon@eu-central-1

DEPLOY_ENV=uat_mon DEPLOY_REGION=eu-central-1 CONFIG_ENV=uat_mon@eu-central-1 make deploy
DEPLOY_ENV=uat_mon DEPLOY_REGION=eu-central-1 CONFIG_KEY=uat_mon@eu-central-1 make deploy
fi

read -p "Deploy MAIN monitoring nodes? (y/N):" mainmonchoice
if [[ $mainmonchoice == "y" ]]; then
make vault-config-update-main_mon@eu-north-1

DEPLOY_ENV=main_mon DEPLOY_REGION=eu-north-1 CONFIG_ENV=main_mon@eu-north-1 make deploy
DEPLOY_ENV=main_mon DEPLOY_REGION=eu-north-1 CONFIG_KEY=main_mon@eu-north-1 make deploy
fi

# Backup nodes
read -p "Deploy UAT backup nodes? (y/N):" backupuatchoice
if [[ $backupuatchoice == "y" ]]; then
make vault-config-update-uat_backup_light
make vault-config-update-uat_backup_full
DEPLOY_ENV=uat_backup DEPLOY_KIND=light CONFIG_ENV=uat_backup_light make deploy
DEPLOY_ENV=uat_backup DEPLOY_KIND=full CONFIG_ENV=uat_backup_full make deploy
DEPLOY_ENV=uat_backup DEPLOY_KIND=light CONFIG_KEY=uat_backup_light make deploy
DEPLOY_ENV=uat_backup DEPLOY_KIND=full CONFIG_KEY=uat_backup_full make deploy
fi

read -p "Deploy MAIN backup nodes? (y/N):" backupmainchoice
if [[ $backupmainchoice == "y" ]]; then
make vault-config-update-main_backup_light
make vault-config-update-main_backup_full
DEPLOY_ENV=main_backup DEPLOY_KIND=light CONFIG_ENV=main_backup_light make deploy
DEPLOY_ENV=main_backup DEPLOY_KIND=full CONFIG_ENV=main_backup_full make deploy
DEPLOY_ENV=main_backup DEPLOY_KIND=light CONFIG_KEY=main_backup_light make deploy
DEPLOY_ENV=main_backup DEPLOY_KIND=full CONFIG_KEY=main_backup_full make deploy
fi

# Testnet gateway nodes
Expand Down