2024-09-15 00:42:15 +03:00
|
|
|
---
|
|
|
|
- name: System Setup and Configuration
|
|
|
|
hosts: all
|
2024-09-18 01:06:32 +03:00
|
|
|
become: true
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Set locale to C.UTF-8
|
|
|
|
command: localectl set-locale LANG=C.UTF-8
|
|
|
|
|
2024-09-18 01:06:32 +03:00
|
|
|
- name: Create APT configuration file to assume yes
|
|
|
|
ansible.builtin.copy:
|
|
|
|
dest: /etc/apt/apt.conf.d/90forceyes
|
|
|
|
content: |
|
|
|
|
APT::Get::Assume-Yes "true";
|
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
|
|
|
|
|
|
|
|
2024-09-15 00:42:15 +03:00
|
|
|
- name: Update /etc/bash.bashrc
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.blockinfile:
|
2024-09-15 00:42:15 +03:00
|
|
|
path: /etc/bash.bashrc
|
|
|
|
block: |
|
|
|
|
export HISTTIMEFORMAT='%F, %T '
|
|
|
|
export HISTSIZE=10000
|
|
|
|
export HISTFILESIZE=10000
|
|
|
|
shopt -s histappend
|
|
|
|
export PROMPT_COMMAND='history -a'
|
|
|
|
export HISTCONTROL=ignoredups
|
|
|
|
export LANG=C.UTF-8
|
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
alias ls='ls --color=auto'
|
|
|
|
shopt -s cmdhist
|
2024-09-18 01:06:32 +03:00
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
2024-09-18 01:06:32 +03:00
|
|
|
- name: Update .inputrc for the current user
|
|
|
|
ansible.builtin.blockinfile:
|
|
|
|
path: "{{ ansible_env.HOME }}/.inputrc"
|
2024-09-15 00:42:15 +03:00
|
|
|
block: |
|
|
|
|
"\e[A": history-search-backward
|
|
|
|
"\e[B": history-search-forward
|
2024-09-18 01:06:32 +03:00
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Update ~/.nanorc
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.blockinfile:
|
|
|
|
path: "{{ ansible_env.HOME }}/.nanorc"
|
2024-09-15 00:42:15 +03:00
|
|
|
block: |
|
|
|
|
set nohelp
|
|
|
|
set tabsize 4
|
|
|
|
set tabstospaces
|
|
|
|
set autoindent
|
|
|
|
set positionlog
|
|
|
|
set backup
|
|
|
|
set backupdir /tmp/
|
|
|
|
set locking
|
|
|
|
include /usr/share/nano/*.nanorc
|
2024-09-18 01:06:32 +03:00
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Set hostname
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
hostnamectl set-hostname {{ serverid }}
|
|
|
|
echo "127.0.1.1 {{ serverid }}" >> /etc/hosts
|
|
|
|
|
|
|
|
- name: Update and upgrade apt
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.apt:
|
|
|
|
update_cache: true
|
2024-09-15 00:42:15 +03:00
|
|
|
upgrade: dist
|
2024-09-18 01:06:32 +03:00
|
|
|
force_apt_get: true
|
2024-09-15 00:42:15 +03:00
|
|
|
register: apt_update_result
|
|
|
|
retries: 50
|
|
|
|
delay: 50
|
|
|
|
until: apt_update_result is succeeded
|
|
|
|
|
|
|
|
- name: Install necessary packages
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.apt:
|
2024-09-15 00:42:15 +03:00
|
|
|
name:
|
|
|
|
- apt-transport-https
|
|
|
|
- ca-certificates
|
|
|
|
- curl
|
|
|
|
- software-properties-common
|
|
|
|
- make
|
|
|
|
- iftop
|
|
|
|
- python3
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Install pip package web3
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.pip:
|
2024-09-15 00:42:15 +03:00
|
|
|
name: web3
|
|
|
|
extra_args: --break-system-packages
|
|
|
|
|
|
|
|
- name: Install Docker
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: curl -sL https://get.docker.com | sudo sh -
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Update Docker daemon configuration for journald logging
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.copy:
|
2024-09-15 00:42:15 +03:00
|
|
|
dest: /etc/docker/daemon.json
|
|
|
|
content: |
|
2024-09-18 01:06:32 +03:00
|
|
|
{ "log-driver": "journald" }
|
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Restart Docker
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.service:
|
2024-09-15 00:42:15 +03:00
|
|
|
name: docker
|
|
|
|
state: restarted
|
|
|
|
|
|
|
|
- name: Docker login
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: docker login -u {{ docker_username }} -p {{ docker_password }}
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Update journald log SystemMaxUse=2G configuration
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.lineinfile:
|
2024-09-15 00:42:15 +03:00
|
|
|
path: /etc/systemd/journald.conf
|
|
|
|
line: 'SystemMaxUse=2G'
|
|
|
|
insertafter: EOF
|
2024-09-18 01:06:32 +03:00
|
|
|
create: true
|
|
|
|
marker: ""
|
|
|
|
mode: '0644'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Restart journald
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.service:
|
2024-09-15 00:42:15 +03:00
|
|
|
name: systemd-journald
|
|
|
|
state: restarted
|
|
|
|
|
|
|
|
- name: Setup Foundry
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
mkdir -p ~/foundry && cd ~/foundry
|
|
|
|
curl -L https://foundry.paradigm.xyz | bash
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
|
|
|
|
- name: Run foundryup
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
source ~/.bashrc && foundryup
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
|
2024-09-15 03:00:16 +03:00
|
|
|
- name: Clone repository
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: https://gitea.vvzvlad.xyz/vvzvlad/ritual.git
|
2024-09-18 01:06:32 +03:00
|
|
|
dest: "{{ ansible_env.HOME }}/ritual"
|
2024-09-15 03:00:16 +03:00
|
|
|
version: "{{ git_version }}"
|
|
|
|
force: true
|
|
|
|
async: "{{ 60 * 15 }}"
|
|
|
|
poll: 30
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Update wallet, private key and RPC URL in project
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: bash update.sh {{ wallet }} {{ private_key }} {{ rpc_url }}
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/ritual"
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Remove old Forge and Infernet SDK
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
|
|
|
rm -rf {{ ansible_env.HOME }}/ritual/projects/hello-world/contracts/lib/forge-std
|
|
|
|
rm -rf {{ ansible_env.HOME }}/ritual/projects/hello-world/contracts/lib/infernet-sdk
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Install Forge and Infernet SDK
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
cd ~/foundry && source ~/.bashrc && foundryup
|
|
|
|
cd ~/ritual-says-gm
|
|
|
|
cd projects/hello-world/contracts
|
|
|
|
forge install --no-commit foundry-rs/forge-std
|
|
|
|
forge install --no-commit ritual-net/infernet-sdk
|
|
|
|
args:
|
|
|
|
executable: /bin/bash
|
|
|
|
|
|
|
|
- name: Deploy container
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: project=hello-world make deploy-container
|
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/ritual"
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Deploy contracts
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: project=hello-world make deploy-contracts 2>&1
|
2024-09-15 00:42:15 +03:00
|
|
|
register: contract_deploy_output
|
2024-09-18 01:06:32 +03:00
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/ritual"
|
|
|
|
retries: 2
|
|
|
|
delay: 60
|
|
|
|
failed_when: '"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL" not in contract_output.stdout'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Update CallContract.s.sol with contract address
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
contract_address=$(jq -r '.transactions[0].contractAddress' projects/hello-world/contracts/broadcast/Deploy.s.sol/8453/run-latest.json)
|
|
|
|
checksum_address=$(python3 toChecksumAddress.py $contract_address)
|
|
|
|
sed -i "s/SaysGM(.*/SaysGM($checksum_address);/" projects/hello-world/contracts/script/CallContract.s.sol
|
2024-09-18 01:06:32 +03:00
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/ritual"
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Call contract
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: project=hello-world make call-contract 2>&1
|
2024-09-15 00:42:15 +03:00
|
|
|
register: contract_output
|
2024-09-18 01:06:32 +03:00
|
|
|
args:
|
|
|
|
chdir: "{{ ansible_env.HOME }}/ritual"
|
|
|
|
retries: 2
|
|
|
|
delay: 60
|
|
|
|
failed_when: '"ONCHAIN EXECUTION COMPLETE & SUCCESSFUL" not in contract_output.stdout'
|
2024-09-15 00:42:15 +03:00
|
|
|
|
|
|
|
- name: Set Docker containers to restart unless stopped
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: |
|
2024-09-15 00:42:15 +03:00
|
|
|
docker update --restart unless-stopped hello-world
|
|
|
|
docker update --restart unless-stopped infernet-node
|
|
|
|
docker update --restart unless-stopped deploy-redis-1
|
|
|
|
docker update --restart unless-stopped infernet-anvil
|
|
|
|
docker update --restart unless-stopped deploy-fluentbit-1
|
|
|
|
|
|
|
|
- name: Remove docker login credentials
|
2024-09-18 01:06:32 +03:00
|
|
|
ansible.builtin.shell: rm -rf /root/.docker/config.json
|