Remove Vagrant support and deploy services selectively
This commit is contained in:
parent
ec4f107100
commit
6ffcffa4a8
39
Vagrantfile
vendored
39
Vagrantfile
vendored
|
@ -1,39 +0,0 @@
|
||||||
Vagrant.require_version ">= 2.0.0"
|
|
||||||
PORT = 19022
|
|
||||||
|
|
||||||
def provisioned?(vm="default", provider="virtualbox")
|
|
||||||
File.exist?(".vagrant/machines/#{vm}/#{provider}/action_provision")
|
|
||||||
end
|
|
||||||
|
|
||||||
Vagrant.configure(2) do |config|
|
|
||||||
config.vm.network :private_network, ip: "192.168.56.10"
|
|
||||||
config.vm.network :forwarded_port, guest: PORT, host: PORT
|
|
||||||
|
|
||||||
config.vm.box = "ubuntu/focal64"
|
|
||||||
config.vm.hostname = "datacoop"
|
|
||||||
|
|
||||||
config.vm.provider :virtualbox do |v|
|
|
||||||
v.cpus = 8
|
|
||||||
v.memory = 16384
|
|
||||||
end
|
|
||||||
|
|
||||||
config.vm.provision :ansible do |ansible|
|
|
||||||
ansible.compatibility_mode = "2.0"
|
|
||||||
ansible.playbook = "playbook.yml"
|
|
||||||
ansible.ask_vault_pass = true
|
|
||||||
ansible.verbose = "v"
|
|
||||||
|
|
||||||
# If the VM is already provisioned, we need to use the new port
|
|
||||||
if provisioned?
|
|
||||||
config.ssh.guest_port = PORT
|
|
||||||
ansible.extra_vars = {
|
|
||||||
ansible_port: PORT,
|
|
||||||
from_vagrant: true
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ansible.extra_vars = {
|
|
||||||
from_vagrant: true
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -2,7 +2,7 @@
|
||||||
ask_vault_pass = True
|
ask_vault_pass = True
|
||||||
inventory = datacoop_hosts
|
inventory = datacoop_hosts
|
||||||
interpreter_python = /usr/bin/python3
|
interpreter_python = /usr/bin/python3
|
||||||
remote_user = root
|
remote_user = ansible
|
||||||
retry_files_enabled = True
|
retry_files_enabled = True
|
||||||
use_persistent_connections = True
|
use_persistent_connections = True
|
||||||
forks = 10
|
forks = 10
|
||||||
|
|
28
deploy.sh
28
deploy.sh
|
@ -2,20 +2,15 @@
|
||||||
|
|
||||||
usage () {
|
usage () {
|
||||||
{
|
{
|
||||||
echo "Usage: $0 [--vagrant]"
|
echo "Usage: $0"
|
||||||
echo "Usage: $0 [--vagrant] base"
|
echo "Usage: $0 base"
|
||||||
echo "Usage: $0 [--vagrant] users"
|
echo "Usage: $0 users"
|
||||||
echo "Usage: $0 [--vagrant] services [SERVICE]"
|
echo "Usage: $0 services [--deploy] [SERVICE]"
|
||||||
} >&2
|
} >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
BASE_CMD="ansible-playbook playbook.yml"
|
BASE_CMD="ansible-playbook playbook.yml"
|
||||||
|
DEPLOY="false"
|
||||||
if [ "$1" = "--vagrant" ]; then
|
|
||||||
BASE_CMD="$BASE_CMD --verbose --inventory=vagrant_host"
|
|
||||||
VAGRANT_VAR="from_vagrant"
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
|
if [ -z "$(ansible-galaxy collection list community.general 2>/dev/null)" ]; then
|
||||||
echo "Installing community.general modules"
|
echo "Installing community.general modules"
|
||||||
|
@ -28,19 +23,24 @@ if [ -z "$1" ]; then
|
||||||
else
|
else
|
||||||
case $1 in
|
case $1 in
|
||||||
"services")
|
"services")
|
||||||
|
if [ -n "$2" && "$2" = "--deploy" ]; then
|
||||||
|
DEPLOY="true"
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
echo "Deploying all services!"
|
echo "Deploying all services!"
|
||||||
eval "$BASE_CMD --tags setup_services $(test -z "$VAGRANT_VAR" || printf '%s' "$VAGRANT_VAR=true")"
|
$BASE_CMD --tags setup_services --extra-vars "deploy_services=$DEPLOY"
|
||||||
else
|
else
|
||||||
echo "Deploying service: $2"
|
echo "Deploying service: $2"
|
||||||
$BASE_CMD --tags setup_services --extra-vars '{"single_service": "'"$2"'"'"$(test -z "$VAGRANT_VAR" || printf '%s' ', "'"$VAGRANT_VAR"'": true')"'}'
|
$BASE_CMD --tags setup_services --extra-vars "deploy_services=$DEPLOY" --extra-vars "single_service=$2"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"base")
|
"base")
|
||||||
eval "$BASE_CMD --tags base_only $(test -z "$VAGRANT_VAR" || printf '%s' "$VAGRANT_VAR=true")"
|
$BASE_CMD --tags base_only
|
||||||
;;
|
;;
|
||||||
"users")
|
"users")
|
||||||
eval "$BASE_CMD --tags setup-users $(test -z "$VAGRANT_VAR" || printf '%s' "$VAGRANT_VAR=true")"
|
$BASE_CMD --tags setup-users
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
usage
|
usage
|
||||||
|
|
|
@ -2,4 +2,7 @@
|
||||||
# code: language=ansible
|
# code: language=ansible
|
||||||
---
|
---
|
||||||
ansible_host: 85.209.118.134
|
ansible_host: 85.209.118.134
|
||||||
fqdn: cavall.servers.data.coop
|
ansible_port: 22
|
||||||
|
|
||||||
|
hostname: "{{ inventory_hostname }}"
|
||||||
|
fqdn: "{{ hostname }}.servers.data.coop"
|
||||||
|
|
|
@ -3,4 +3,9 @@
|
||||||
---
|
---
|
||||||
ansible_host: 85.209.118.134
|
ansible_host: 85.209.118.134
|
||||||
ansible_port: 19022
|
ansible_port: 19022
|
||||||
fqdn: folald.vm.cavall.servers.data.coop
|
|
||||||
|
vm_host: cavall
|
||||||
|
vm_type: qemu
|
||||||
|
|
||||||
|
hostname: "{{ inventory_hostname }}"
|
||||||
|
fqdn: "{{ hostname }}.vm.{{ vm_host }}.servers.data.coop"
|
||||||
|
|
|
@ -2,4 +2,10 @@
|
||||||
# code: language=ansible
|
# code: language=ansible
|
||||||
---
|
---
|
||||||
ansible_host: 159.223.17.241
|
ansible_host: 159.223.17.241
|
||||||
fqdn: hestur.servers.data.coop
|
ansible_port: 22
|
||||||
|
|
||||||
|
vm_host: cloud
|
||||||
|
vm_type: vps
|
||||||
|
|
||||||
|
hostname: "{{ inventory_hostname }}"
|
||||||
|
fqdn: "{{ hostname }}.vm.{{ vm_host }}.servers.data.coop"
|
||||||
|
|
|
@ -3,4 +3,9 @@
|
||||||
---
|
---
|
||||||
ansible_host: 85.209.118.142
|
ansible_host: 85.209.118.142
|
||||||
ansible_port: 19022
|
ansible_port: 19022
|
||||||
fqdn: poltre.vm.cavall.servers.data.coop
|
|
||||||
|
vm_host: cavall
|
||||||
|
vm_type: qemu
|
||||||
|
|
||||||
|
hostname: "{{ inventory_hostname }}"
|
||||||
|
fqdn: "{{ hostname }}.vm.{{ vm_host }}.servers.data.coop"
|
||||||
|
|
|
@ -3,4 +3,9 @@
|
||||||
---
|
---
|
||||||
ansible_host: 85.209.118.143
|
ansible_host: 85.209.118.143
|
||||||
ansible_port: 19022
|
ansible_port: 19022
|
||||||
fqdn: varsa.vm.cavall.servers.data.coop
|
|
||||||
|
vm_host: cavall
|
||||||
|
vm_type: qemu
|
||||||
|
|
||||||
|
hostname: "{{ inventory_hostname }}"
|
||||||
|
fqdn: "{{ hostname }}.vm.{{ vm_host }}.servers.data.coop"
|
||||||
|
|
|
@ -16,4 +16,7 @@ folald
|
||||||
[virtual:children]
|
[virtual:children]
|
||||||
production
|
production
|
||||||
staging
|
staging
|
||||||
control
|
control
|
||||||
|
|
||||||
|
[physical:children]
|
||||||
|
proxmox
|
|
@ -1,27 +1,30 @@
|
||||||
# vim: ft=yaml.ansible
|
# vim: ft=yaml.ansible
|
||||||
# code: language=ansible
|
# code: language=ansible
|
||||||
---
|
---
|
||||||
- name: Create volume folder for service {{ service.name }}
|
- name: Create volume folder for service '{{ service.name }}'
|
||||||
file:
|
file:
|
||||||
name: "{{ service.vars.volume_folder }}"
|
name: "{{ service.vars.volume_folder }}"
|
||||||
state: directory
|
state: directory
|
||||||
|
|
||||||
- name: Upload Compose file for service {{ service.name }}
|
- name: Upload Compose file for service '{{ service.name }}'
|
||||||
template:
|
template:
|
||||||
src: compose-files/{{ service.name }}.yml.j2
|
src: compose-files/{{ service.name }}.yml.j2
|
||||||
dest: "{{ service.vars.volume_folder }}/docker-compose.yml"
|
dest: "{{ service.vars.volume_folder }}/docker-compose.yml"
|
||||||
owner: root
|
owner: root
|
||||||
mode: u=rw,go=
|
mode: u=rw,go=
|
||||||
|
|
||||||
- name: Run pre-deployment tasks for service {{ service.name }}
|
- name: Run pre-deployment tasks for service '{{ service.name }}'
|
||||||
include_tasks: pre_deploy/{{ service.name }}.yml
|
ansible.builtin.include_tasks: pre_deploy/{{ service.name }}.yml
|
||||||
when: service.vars.pre_deploy_tasks is defined and service.vars.pre_deploy_tasks
|
when: service.vars.pre_deploy_tasks is defined and service.vars.pre_deploy_tasks
|
||||||
|
|
||||||
- name: Deploy Compose stack for service {{ service.name }}
|
- name: Deploy service '{{ service.name }}'
|
||||||
command: docker compose up -d --remove-orphans --pull always
|
when: deploy_services is defined and deploy_services
|
||||||
args:
|
block:
|
||||||
chdir: "{{ service.vars.volume_folder }}"
|
- name: Deploy Compose stack for service '{{ service.name }}'
|
||||||
|
ansible.builtin.command: docker compose up -d --remove-orphans --pull always
|
||||||
|
args:
|
||||||
|
chdir: "{{ service.vars.volume_folder }}"
|
||||||
|
|
||||||
- name: Run post-deployment tasks for service {{ service.name }}
|
- name: Run post-deployment tasks for service '{{ service.name }}'
|
||||||
include_tasks: post_deploy/{{ service.name }}.yml
|
ansible.builtin.include_tasks: post_deploy/{{ service.name }}.yml
|
||||||
when: service.vars.post_deploy_tasks is defined and service.vars.post_deploy_tasks
|
when: service.vars.post_deploy_tasks is defined and service.vars.post_deploy_tasks
|
||||||
|
|
|
@ -7,8 +7,8 @@ services:
|
||||||
backup:
|
backup:
|
||||||
image: mazzolino/restic:{{ services.restic.version }}
|
image: mazzolino/restic:{{ services.restic.version }}
|
||||||
restart: always
|
restart: always
|
||||||
hostname: {{ inventory_hostname_short }}
|
hostname: {{ hostname }}
|
||||||
domainname: {{ inventory_hostname }}
|
domainname: {{ fqdn }}
|
||||||
environment:
|
environment:
|
||||||
RUN_ON_STARTUP: false
|
RUN_ON_STARTUP: false
|
||||||
BACKUP_CRON: "0 30 3 * * *"
|
BACKUP_CRON: "0 30 3 * * *"
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
# vim: ft=yaml.ansible
|
# vim: ft=yaml.ansible
|
||||||
# code: language=ansible
|
# code: language=ansible
|
||||||
---
|
---
|
||||||
- ansible.builtin.import_tasks: ssh-port.yml
|
|
||||||
tags: [change-ssh-port]
|
|
||||||
when: ansible_port != 22
|
|
||||||
|
|
||||||
- ansible.builtin.import_tasks: base.yml
|
- ansible.builtin.import_tasks: base.yml
|
||||||
tags: [install-base-packages]
|
tags: [install-base-packages]
|
||||||
|
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
[production]
|
|
||||||
localhost ansible_port=19022
|
|
Loading…
Reference in a new issue