create shadow docker swarm

This commit is contained in:
Pim Kunis 2024-02-06 22:03:25 +01:00
parent 701cc85327
commit ab8ae06040
3 changed files with 50 additions and 13 deletions

View file

@ -1,9 +1,11 @@
all: all:
hosts: hosts:
manager: primary:
ansible_host: 192.168.30.42 ansible_host: 192.168.30.42
children: children:
workers: secondaries:
hosts: hosts:
bancomart: bancomart:
ansible_host: bancomart2.dmz ansible_host: bancomart2.dmz
vpay:
ansible_host: vpay2.dmz

View file

@ -1,23 +1,23 @@
--- ---
- name: Setup Docker Swarm manager - name: Setup Docker Swarm primary
hosts: manager hosts: primary
tasks: tasks:
- name: Create Docker Swarm - name: Create Docker Swarm
docker_swarm: docker_swarm:
- name: Get Docker Swarm manager info - name: Get Docker Swarm primary info
docker_swarm_info: docker_swarm_info:
nodes: yes nodes: yes
nodes_filters: nodes_filters:
name: manager name: primary
register: swarm_info register: swarm_info
- hosts: workers - hosts: secondaries
tasks: tasks:
- name: Join Docker Swarm - name: Join Docker Swarm
docker_swarm: docker_swarm:
state: join state: join
join_token: "{{ hostvars.manager.swarm_info.swarm_facts.JoinTokens.Worker }}" join_token: "{{ hostvars.primary.swarm_info.swarm_facts.JoinTokens.Manager }}"
remote_addrs: remote_addrs:
- "{{ hostvars.manager.ansible_default_ipv4.address }}" - "{{ hostvars.primary.ansible_default_ipv4.address }}"

View file

@ -58,6 +58,7 @@
}; };
}; };
# TODO: make leases persistent!
hermes = { hermes = {
type = "virtual"; type = "virtual";
hypervisorName = "lewis"; hypervisorName = "lewis";
@ -79,7 +80,7 @@
maestro2 = { maestro2 = {
type = "virtual"; type = "virtual";
hypervisorName = "lewis"; hypervisorName = "atlas";
nixosModule = { pkgs, lib, config, ... }: { nixosModule = { pkgs, lib, config, ... }: {
lab.vm = { lab.vm = {
@ -90,7 +91,7 @@
}; };
microvm.shares = [{ microvm.shares = [{
source = "/var/lib/microvms/${config.networking.hostName}/shares/docker_swarm"; source = "/data/vm_shares/${config.networking.hostName}/docker_swarm";
mountPoint = "/var/lib/docker/swarm"; mountPoint = "/var/lib/docker/swarm";
tag = "docker_swarm"; tag = "docker_swarm";
proto = "virtiofs"; proto = "virtiofs";
@ -118,13 +119,47 @@
bancomart2 = { bancomart2 = {
type = "virtual"; type = "virtual";
hypervisorName = "lewis"; hypervisorName = "jefke";
nixosModule = { pkgs, lib, config, ... }: { nixosModule = { pkgs, lib, config, ... }: {
lab.vm.id = 2; lab.vm.id = 2;
microvm.shares = [{ microvm.shares = [{
source = "/var/lib/microvms/${config.networking.hostName}/shares/docker_swarm"; source = "/data/vm_shares/${config.networking.hostName}/docker_swarm";
mountPoint = "/var/lib/docker/swarm";
tag = "docker_swarm";
proto = "virtiofs";
socket = "docker_swarm.sock";
}];
networking = {
nftables.enable = lib.mkForce false;
firewall.enable = lib.mkForce false;
};
virtualisation.docker = {
enable = true;
liveRestore = false;
};
environment.systemPackages = with pkgs; [
(python311.withPackages (python-pkgs: [
python-pkgs.docker
python-pkgs.requests
]))
];
};
};
vpay2 = {
type = "virtual";
hypervisorName = "lewis";
nixosModule = { pkgs, lib, config, ... }: {
lab.vm.id = 3;
microvm.shares = [{
source = "/data/vm_shares/${config.networking.hostName}/docker_swarm";
mountPoint = "/var/lib/docker/swarm"; mountPoint = "/var/lib/docker/swarm";
tag = "docker_swarm"; tag = "docker_swarm";
proto = "virtiofs"; proto = "virtiofs";