1
0

Compare commits

...

3 Commits

10 changed files with 82 additions and 110 deletions

View File

@ -7,70 +7,24 @@ vars:
sh: 'id -u'
GROUP_ID:
sh: 'id -g'
HOSTS_FILE: 'ansible/hosts_prod'
REMOTE_USER: 'major'
HOSTS_FILE: 'production.yml'
REMOTE_USER:
sh: 'yq .ungrouped.hosts.server.ansible_user {{.HOSTS_FILE}}'
REMOTE_HOST:
sh: 'cat {{.HOSTS_FILE}} | xargs'
sh: 'yq .ungrouped.hosts.server.ansible_host {{.HOSTS_FILE}}'
tasks:
ssh:
cmds:
- ssh {{.REMOTE_USER}}@{{.REMOTE_HOST}}
- ssh {{.REMOTE_USER}}@{{.REMOTE_HOST}}
edit-vars:
cmds:
- ansible-vault edit ansible/vars/vars.yml
- ansible-vault edit vars/vars.yml
env:
EDITOR: micro
list-tags:
cmds:
- >-
ansible-playbook
--inventory="{{.HOSTS_FILE}}"
--list-tags
ansible/configuration.yml
configure:
internal: true
vars:
TAGS: '{{ (empty .TAGS) | ternary "" (list "--tags=\"" .TAGS "\"" | join "") }}'
cmds:
- >-
ansible-playbook
--become
--user="{{.REMOTE_USER}}"
--inventory="{{.HOSTS_FILE}}"
--extra-vars="ansible_python_interpreter=/usr/bin/python3"
{{.TAGS}}
ansible/configuration.yml
configure-all:
cmds:
- task: configure
configure-monitoring:
cmds:
- task: configure
vars: { TAGS: 'monitoring' }
configure-apps:
cmds:
- task: configure
vars: { TAGS: 'webserver,apps,env' }
configure-users:
cmds:
- task: configure
vars: { TAGS: 'apps,env' }
format-py-files:
cmds:
- >-
docker run
--rm
-u {{.USER_ID}}:{{.GROUP_ID}}
-v $PWD:/app
-w /app
pyfound/black:latest_release
black .
- >-
docker run --rm -u {{.USER_ID}}:{{.GROUP_ID}} -v $PWD:/app -w /app pyfound/black:latest_release black .

View File

@ -1 +0,0 @@
158.160.46.255

27
playbook-caddy.yml Normal file
View File

@ -0,0 +1,27 @@
---
- name: 'Install and configure Caddy server'
hosts: all
vars_files:
- vars/ports.yml
- vars/vars.yml
tasks:
- name: 'Ensure networkd service is started (required by Caddy).'
ansible.builtin.systemd:
name: systemd-networkd
state: started
enabled: true
- name: 'Install and configure Caddy server'
ansible.builtin.import_role:
name: caddy_ansible.caddy_ansible
vars:
caddy_github_token: '{{ caddy_vars.github_token }}'
caddy_config: '{{ lookup("template", "templates/Caddyfile.j2") }}'
caddy_setcap: true
caddy_systemd_capabilities_enabled: true
caddy_systemd_capabilities: "CAP_NET_BIND_SERVICE"
# Поменяй на true, чтобы обновить Caddy
caddy_update: false

View File

@ -7,26 +7,6 @@
tasks:
- name: 'Ensure networkd service is started (required by Caddy).'
systemd:
name: systemd-networkd
state: started
enabled: true
tags:
- webserver
- import_role:
name: caddy_ansible.caddy_ansible
vars:
caddy_github_token: '{{ caddy_vars.github_token }}'
caddy_config: '{{ lookup("template", "templates/Caddyfile.j2") }}'
caddy_update: False
caddy_setcap: True
caddy_systemd_capabilities_enabled: True
caddy_systemd_capabilities: "CAP_NET_BIND_SERVICE"
tags:
- webserver
# Applications
- import_role:

View File

@ -0,0 +1,27 @@
---
- name: 'Update and upgrade system packages'
hosts: all
vars_files:
- vars/ports.yml
- vars/vars.yml
vars:
user_name: '<put-name-here>'
tasks:
- name: 'Remove user "{{ user_name }}"'
ansible.builtin.user:
name: '{{ user_name }}'
state: absent
remove: true
- name: 'Remove group "{{ user_name }}"'
ansible.builtin.group:
name: '{{ user_name }}'
state: absent
- name: 'Remove web dir'
ansible.builtin.file:
path: '/var/www/{{ user_name }}'
state: absent

View File

@ -10,6 +10,7 @@
apt_packages:
- acl
- git
- htop
- python3-pip
tasks:

View File

@ -10,18 +10,18 @@
- name: Perform an upgrade of packages
ansible.builtin.apt:
upgrade: 'yes'
update_cache: yes
update_cache: true
- name: Check if a reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
get_checksum: no
get_checksum: false
register: reboot_required_file
- name: Reboot the server (if required)
ansible.builtin.reboot:
when: reboot_required_file.stat.exists == true
when: reboot_required_file.stat.exists
- name: Remove dependencies that are no longer required
ansible.builtin.apt:
autoremove: yes
autoremove: true

7
production.yml Normal file
View File

@ -0,0 +1,7 @@
---
ungrouped:
hosts:
server:
ansible_host: '158.160.46.255'
ansible_user: 'major'
ansible_become: true

View File

@ -53,7 +53,5 @@ def deploy(app_name: str, compose_file="docker-compose.yml", dirs=None):
c.run(
f"docker compose --project-name {shlex.quote(app_name)} --env-file=.env.prod up --detach --remove-orphans"
)
c.run(
f"docker system prune --all --volumes --force"
)
c.run(f"docker system prune --all --volumes --force")
print("Done.")

View File

@ -7,18 +7,9 @@
}
# -------------------------------------------------------------------
# Proxy services
# Netdata service
# -------------------------------------------------------------------
vakhrushev.me {
tls anwinged@ya.ru
reverse_proxy {
to 127.0.0.1:{{ homepage_port }}
}
}
# NetData proxy
status.vakhrushev.me, :29999 {
tls anwinged@ya.ru
@ -31,27 +22,15 @@ status.vakhrushev.me, :29999 {
}
}
wiki.vakhrushev.me {
# -------------------------------------------------------------------
# Applications
# -------------------------------------------------------------------
vakhrushev.me {
tls anwinged@ya.ru
reverse_proxy {
to 127.0.0.1:{{ wiki_port }}
}
}
nomie.vakhrushev.me {
tls anwinged@ya.ru
reverse_proxy {
to 127.0.0.1:{{ nomie_port }}
}
}
nomie-db.vakhrushev.me {
tls anwinged@ya.ru
reverse_proxy {
to 127.0.0.1:{{ nomie_db_port }}
to 127.0.0.1:{{ homepage_port }}
}
}