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

feat: fix check mode for eth and core roles #7

Merged
1 change: 1 addition & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mock_modules:
- community.postgresql.postgresql_db
- community.postgresql.postgresql_user
- community.postgresql.postgresql_owner
- community.docker.docker_image
40 changes: 40 additions & 0 deletions roles/docker/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
- name: Install software
ansible.builtin.apt:
update_cache: true
name:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common

- name: Add apt key for required repositories
ansible.builtin.apt_key:
url: '{{ item }}'
state: present
with_items:
# docker
- https://download.docker.com/linux/ubuntu/gpg

- name: Add required source repositories into sources list
ansible.builtin.apt_repository:
repo: '{{ item }}'
state: present
with_items:
- "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"

- name: Install software
ansible.builtin.apt:
update_cache: true
name:
- docker-ce
- docker-ce-cli
- containerd.io
- docker-buildx-plugin
- docker-compose-plugin

- name: Restart docker
ansible.builtin.systemd:
state: restarted
daemon_reload: true
name: docker
2 changes: 2 additions & 0 deletions roles/geth/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
remote_src: true
dest: /tmp
extra_opts: ['--strip-components=1', '--show-stored-names']
when: not ansible_check_mode

- name: Copy geth binary
ansible.builtin.copy:
Expand All @@ -26,3 +27,4 @@
owner: root
group: root
mode: '0755'
when: not ansible_check_mode
3 changes: 2 additions & 1 deletion roles/grafana_agent/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
grafana_agent_version: 0.43.0
grafana_agent_repository: grafana/agent
# config template may be loaded when the lookup plugin is enabled with the following snipped "{{ lookup('file', 'configs/grafana-agent-monitoring-template.yaml') }}"
# config template may be loaded when the lookup plugin is enabled with the following snipped:
# "{{ lookup('file', 'configs/grafana-agent-monitoring-template.yaml') }}"
grafana_agent_config_content: "# empty content"
3 changes: 2 additions & 1 deletion roles/grafana_agent/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
- name: Restart grafana-agent
ansible.builtin.service:
name: grafana-agent
state: restarted
listen: Restart grafana-agent
when: not ansible_check_mode
when: not ansible_check_mode
2 changes: 1 addition & 1 deletion roles/grafana_agent/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Grafana Agent | Install grafana-agent
ansible.builtin.apt:
deb: "https://github.com/{{- grafana_agent_repository -}}/releases/download/v{{- grafana_agent_version -}}/grafana-agent-{{- grafana_agent_version -}}-1.amd64.deb"
deb: "https://github.com/{{- grafana_agent_repository -}}/releases/download/v{{- grafana_agent_version -}}/grafana-agent-{{- grafana_agent_version -}}-1.amd64.deb" # noqa: yaml[line-length]

- name: Grafana Agent | Update CUSTOM_ARGS environment variables for grafana config
ansible.builtin.lineinfile:
Expand Down
10 changes: 10 additions & 0 deletions roles/pyth_price_scheduler/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
pyth_price_scheduler_docker_image: public.ecr.aws/pyth-network/xc-price-pusher:v8.0.0
pyth_price_scheduler_mnemonic: "PUT_PRIVATE_KEY_HERE"
pyth_price_scheduler_endpoint: "PUT_HERE_RPC_URL"
pyth_price_scheduler_contract_address: "PUT_HERE_CONTRACT_ADDRESS"
pyth_price_scheduler_service_endpoint: https://hermes.pyth.network
pyth_price_scheduler_price_config_content: "PUT_CONFIG_HERE"

pyth_price_scheduler_process_watcher_version: "v0.1.0"
pyth_price_scheduler_process_watcher_repository: "vegaprotocol/process-watcher"
6 changes: 6 additions & 0 deletions roles/pyth_price_scheduler/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Process watcher
ansible.builtin.import_tasks: process-watcher.yaml

- name: Price pusher
ansible.builtin.import_tasks: price-pusher.yaml
62 changes: 62 additions & 0 deletions roles/pyth_price_scheduler/tasks/price-pusher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
- name: Install python packages for Ansible
ansible.builtin.pip:
name:
- docker

- name: Pull an price scheduler docker image
community.docker.docker_image:
name: "{{- pyth_price_scheduler_docker_image -}}"
source: pull
pull:
platform: amd64

- name: Ensure group "pyth-price-scheduler" exists
ansible.builtin.group:
name: pyth-price-scheduler
state: present

- name: Add the user "pyth-price-scheduler"
ansible.builtin.user:
name: pyth-price-scheduler
comment: Price scheduler
groups: pyth-price-scheduler,docker

- name: Copy service file
ansible.builtin.template:
src: "lib/systemd/system/pyth-price-scheduler.service.j2"
dest: "/lib/systemd/system/pyth-price-scheduler.service"
owner: root
group: root
mode: '0644'

- name: "Create config directory for the pyth-price-scheduler"
ansible.builtin.file:
path: "/home/pyth-price-scheduler"
state: directory
owner: pyth-price-scheduler
group: pyth-price-scheduler
mode: '0755'

- name: Copy config file
ansible.builtin.copy:
dest: "/home/pyth-price-scheduler/price-config.yaml"
content: "{{ pyth_price_scheduler_price_config_content }}"
owner: pyth-price-scheduler
group: pyth-price-scheduler
mode: "0644"

- name: Save mnemonic
ansible.builtin.copy:
owner: pyth-price-scheduler
group: pyth-price-scheduler
content: "{{- pyth_price_scheduler_mnemonic -}}"
dest: /home/pyth-price-scheduler/mnemonic
mode: "0644"

- name: Start and enable systemd service for pyth-price-scheduler
ansible.builtin.service:
name: "pyth-price-scheduler"
state: restarted
enabled: true
daemon_reload: true
44 changes: 44 additions & 0 deletions roles/pyth_price_scheduler/tasks/process-watcher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Download binary
ansible.builtin.get_url:
url: "https://github.com/{{- pyth_price_scheduler_process_watcher_repository -}}/releases/download/{{- pyth_price_scheduler_process_watcher_version -}}/process-watcher-linux-amd64.zip" # noqa: yaml[line-length]
dest: &watcherdist /tmp/process-watcher.tar.gz
mode: '0600'

- name: Unpack binary
ansible.builtin.unarchive:
src: *watcherdist
remote_src: true
dest: /tmp

- name: Copy the binary
ansible.builtin.copy:
remote_src: true
src: "/tmp/process-watcher"
dest: /usr/bin/process-watcher
owner: root
group: root
mode: '0755'

- name: Copy process watcher config
ansible.builtin.template:
src: "etc/pyth-process-watcher-config.toml"
dest: "/etc/pyth-process-watcher-config.toml"
owner: root
group: root
mode: '0644'

- name: Copy process watcher service file
ansible.builtin.template:
src: "lib/systemd/system/pyth-process-watcher.service.j2"
dest: "/lib/systemd/system/pyth-process-watcher.service"
owner: root
group: root
mode: '0644'

- name: Start pusher watcher service
ansible.builtin.service:
name: "pyth-process-watcher"
state: restarted
enabled: true
daemon_reload: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[commands]
# Define the log stream command
log-stream = [
"/usr/bin/journalctl",
"-u", "pyth-price-scheduler",
"-n", "1",
"-f",
]
# Define the command used to stop the service
stop = ["/usr/bin/systemctl", "stop", "pyth-price-scheduler"]
# Define the command to start the service
start = ["/usr/bin/systemctl", "start", "pyth-price-scheduler"]


[process-watcher]
# Watches if specific docker container is running
[process-watcher.docker]
enabled = true
container-name = "pyth-price-scheduler"

[logs-watcher]
# Define the keywords that trigger process restart
failure-keywords = ["err", "failed", "throw err", "error"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[Unit]
Description=Pyth price pusher
Documentation=https://github.com/pyth-network/pyth-crosschain/tree/main/price_pusher
After=docker.service
Requires=docker.service

[Service]
User=pyth-price-scheduler
Group=pyth-price-scheduler
TimeoutStartSec=0
Restart=always
ExecStop=/usr/bin/docker kill pyth-price-scheduler
ExecStartPre=-/usr/bin/docker stop pyth-price-scheduler
ExecStartPre=-/usr/bin/docker rm pyth-price-scheduler
ExecStartPre=/usr/bin/docker pull {{ pyth_price_scheduler_docker_image }}
ExecStart=/usr/bin/docker run \
--name pyth-price-scheduler \
-v /home/pyth-price-scheduler:/config \
{{ pyth_price_scheduler_docker_image }} \
npm run start -- \
evm \
--endpoint "{{- pyth_price_scheduler_endpoint -}}" \
--mnemonic-file "/config/mnemonic" \
--pyth-contract-address "{{- pyth_price_scheduler_contract_address -}}" \
--price-service-endpoint "{{- pyth_price_scheduler_service_endpoint -}}" \
--price-config-file "/config/price-config.yaml" \
--polling-frequency 5


[Install]
WantedBy=multi-user.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Pyth price process watcher
Documentation=https://github.com/vegaprotocol/process-watcher
After=docker.service
Requires=docker.service
After=network.target network-online.target
Requires=network-online.target

[Service]
User=root
Group=root
TimeoutStartSec=0
Restart=always
ExecStart=/usr/bin/process-watcher run --config-path /etc/pyth-process-watcher-config.toml

[Install]
WantedBy=multi-user.target
8 changes: 8 additions & 0 deletions roles/vega_common/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
- acl
- unzip
- gzip
- tar
- bzip2

- name: Install Python and pip
ansible.builtin.apt:
pkg:
- python3
- python3-pip

- name: Ensure group "vega" exists
ansible.builtin.group:
Expand Down
4 changes: 4 additions & 0 deletions roles/vega_core/tasks/get-binaries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
src: *vega_dest
remote_src: true
dest: /tmp
when: not ansible_check_mode

- name: Copy vega binary
ansible.builtin.copy:
Expand All @@ -20,6 +21,7 @@
owner: root
group: root
mode: '0755'
when: not ansible_check_mode

- name: Download visor binary
ansible.builtin.get_url:
Expand All @@ -33,6 +35,7 @@
src: *visor_dest
remote_src: true
dest: /tmp
when: not ansible_check_mode

- name: Copy visor binary
ansible.builtin.copy:
Expand All @@ -42,3 +45,4 @@
owner: root
group: root
mode: '0755'
when: not ansible_check_mode