1
0

Migrate inventory to yaml

This commit is contained in:
Anton Vakhrushev 2024-12-21 15:11:01 +03:00
parent 98a1087e84
commit cd86348f88
Signed by: av
GPG Key ID: F5BF52FC352E255A
5 changed files with 17 additions and 58 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

View File

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

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.")