dabo/dabo-ansible.yml
2024-12-18 15:14:39 +01:00

153 lines
4.8 KiB
YAML

---
- name: dabo
hosts: all
tasks:
- name: Create /home/docker/dabo.{{inventory_hostname}} dir
ansible.builtin.file:
path: /home/docker/dabo.{{inventory_hostname}}
owner: root
group: docker
state: directory
mode: '0550'
- name: Git checkout
ansible.builtin.git:
repo: 'https://github.com/egabosh/dabo.git'
dest: /home/docker/dabo.{{inventory_hostname}}
force: true
notify: Restart dabo
- name: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
blockinfile:
path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
create: yes
mode: 0550
owner: root
group: docker
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
cd /home/docker/dabo.{{inventory_hostname}}
if ! [ -d home/.ssh ]
then
mkdir -p home/.ssh
ssh-keygen -f home/.ssh/id_ed25519 -N "" -t ed25519 >/dev/null
chmod 700 home/.ssh
fi
mkdir -p data/botdata strategies
chown -R 10000:10000 dabo data home strategies dabo-bot.conf
backup: yes
validate: /bin/bash -n %s
notify: run initiate.sh
- name: /home/docker/dabo.{{inventory_hostname}}/initiate.sh shebang
lineinfile:
path: /home/docker/dabo.{{inventory_hostname}}/initiate.sh
insertbefore: BOF
line: "#!/bin/bash -e"
- name: Basic dabo config
blockinfile:
path: /home/docker/dabo.{{inventory_hostname}}/dabo-bot.conf
create: yes
mode: 0440
owner: 10000
group: 10000
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
URL=dabo.{{inventory_hostname}}
validate: /bin/bash -n %s
backup: yes
notify:
- Restart dabo
#- name: Get crypted PW
# shell: bash /home/docker/dabo.{{inventory_hostname}}/initiate.sh
# register: cryptpw
# changed_when: false
- name: /home/docker/dabo.{{inventory_hostname}}/docker-compose.override.yml Container Configuration
blockinfile:
path: /home/docker/dabo.{{inventory_hostname}}/docker-compose.override.yml
create: yes
mode: 0440
owner: root
group: docker
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
networks:
dabo-network:
driver: bridge
driver_opts:
com.docker.network.bridge.name: br-dabo
traefik:
external: true
services:
dabo-bot:
networks:
- traefik
- dabo-network
dabo-web:
labels:
- traefik.enable=true
# HTTPS
- traefik.http.routers.dabo.rule=Host(`dabo.{{inventory_hostname}}`)
- traefik.http.routers.dabo.entrypoints=https
- traefik.http.routers.dabo.tls=true
# Proxy to service-port
- traefik.http.services.dabo.loadbalancer.server.port=80
- traefik.http.routers.dabo.service=dabo
# cert via letsencrypt
- traefik.http.routers.dabo.tls.certresolver=letsencrypt
# activate secHeaders@file
- traefik.http.routers.dabo.middlewares=secHeaders@file,default-basic-auth@file
# Traefik network
- traefik.docker.network=traefik
networks:
- traefik
backup: yes
notify: Restart dabo
- name: Build dabo-bot
ansible.builtin.shell: docker -l warn compose --ansi never build --progress=plain --pull --no-cache --force-rm
args:
chdir: /home/docker/dabo.{{inventory_hostname}}
creates: /home/docker/dabo.{{inventory_hostname}}/data/botdata/MARKET_PERFORMANCE
- name: autoupdate dabo-bot
blockinfile:
path: /usr/local/sbin/autoupdate.d/dabo.update
create: yes
mode: 0550
owner: root
group: root
marker: "# {mark} ANSIBLE MANAGED BLOCK"
block: |
g_echo_ok "Dabo update"
rm -f /tmp/dabo-ansible.yml
wget https://raw.githubusercontent.com/egabosh/dabo/refs/heads/main/dabo-ansible.yml -O /tmp/dabo-ansible.yml
ansible-playbook --connection=local --inventory $(hostname), --limit $(hostname) /tmp/dabo-ansible.yml
backup: yes
validate: /bin/bash -n %s
handlers:
- name: run initiate.sh
ansible.builtin.shell: ./initiate.sh
args:
chdir: /home/docker/dabo.{{inventory_hostname}}
notify: Restart dabo
- name: Restart dabo
ansible.builtin.shell: docker compose up -d --force-recreate
args:
chdir: /home/docker/dabo.{{inventory_hostname}}