diff --git a/group_vars/asgard/vars.yml b/group_vars/asgard/vars.yml index ba289e8..80a04a3 100644 --- a/group_vars/asgard/vars.yml +++ b/group_vars/asgard/vars.yml @@ -57,6 +57,7 @@ services: smtp_host: "{{ vault_services.git.smtp_host }}" smtp_user: "{{ vault_services.git.smtp_user }}" smtp_passwd: "{{ vault_services.git.smtp_passwd }}" + ssh_port: 2770 notes: domain: "{{ vault_services.notes.domain }}" database_name: "{{ vault_services.notes.database_name }}" diff --git a/host_vars/yggdrasil/vars.yml b/host_vars/yggdrasil/vars.yml index fe2abc7..73472f9 100644 --- a/host_vars/yggdrasil/vars.yml +++ b/host_vars/yggdrasil/vars.yml @@ -44,6 +44,6 @@ services_host_services: address: "{{ vpn_bridge_prefix }}.4" git: address: "{{ vpn_bridge_prefix }}.5" - tcp: [2770] + tcp: ["{{ services.git.ssh_port }}"] notes: address: "{{ vpn_bridge_prefix }}.6" diff --git a/plays/services/main.yml b/plays/services/main.yml index 7aaf8a5..6997cd0 100644 --- a/plays/services/main.yml +++ b/plays/services/main.yml @@ -113,3 +113,16 @@ vars: services_service_name: "cloud" tags: "always" + + - name: "deploy" + ansible.builtin.include_role: + name: "deploy/git" + apply: + tags: + - "services:{{ services_service_name }}" + - "services:deploy" + - "services:deploy:{{ services_service_name }}" + - "services:{{ services_service_name }}:deploy" + vars: + services_service_name: "git" + tags: "always" diff --git a/plays/services/roles/deploy/git/tasks/main.yml b/plays/services/roles/deploy/git/tasks/main.yml new file mode 100644 index 0000000..7f2a238 --- /dev/null +++ b/plays/services/roles/deploy/git/tasks/main.yml @@ -0,0 +1,52 @@ +- name: "set the user variables" + ansible.builtin.import_role: + name: "include" + vars_from: "user" + +- name: "set the version variables" + ansible.builtin.import_role: + name: "deploy/include" + vars_from: "versions" + +- block: + + - name: "configure systemd service" + ansible.builtin.template: + src: "./systemd/{{ item }}.j2" + dest: "{{ services_service_user_home }}/.config/systemd/user/{{ item }}" + mode: 0644 + loop: + - "pod-git.service" + - "container-git-gitea.service" + register: services_deploy_git_systemd_files + + - name: "systemd user daemon reload" + ansible.builtin.systemd: + daemon_reload: true + scope: "user" + when: + services_deploy_git_systemd_files.changed + + - name: "enable the service" + ansible.builtin.systemd: + name: "pod-{{ services_service_name }}.service" + enabled: true + scope: "user" + + - name: "start the service" + ansible.builtin.systemd: + name: "pod-{{ services_service_name }}.service" + state: "started" + scope: "user" + register: services_deploy_git_service_start + + - name: "restart the service" + ansible.builtin.systemd: + name: "pod-{{ services_service_name }}.service" + state: restarted + scope: user + when: + services_deploy_git_systemd_files.changed and + not services_deploy_git_service_start.changed + + become_user: "{{ services_service_user_name }}" diff --git a/playbooks/filesystem/yggdrasil/var/lib/yggdrasil/home/pod-git/.config/systemd/user/container-git-gitea.service.j2 b/plays/services/roles/deploy/git/templates/systemd/container-git-gitea.service.j2 similarity index 81% rename from playbooks/filesystem/yggdrasil/var/lib/yggdrasil/home/pod-git/.config/systemd/user/container-git-gitea.service.j2 rename to plays/services/roles/deploy/git/templates/systemd/container-git-gitea.service.j2 index 449eac2..e65891d 100644 --- a/playbooks/filesystem/yggdrasil/var/lib/yggdrasil/home/pod-git/.config/systemd/user/container-git-gitea.service.j2 +++ b/plays/services/roles/deploy/git/templates/systemd/container-git-gitea.service.j2 @@ -20,7 +20,7 @@ ExecStart=/usr/bin/podman run \ --replace \ --label "io.containers.autoupdate=image" \ -dt \ - --add-host=pod-database:{{ services['database'].address }} \ + --add-host=pod-database:{{ services_all_services['database'].address }} \ -v /var/lib/yggdrasil/valkyrie-resolv.conf:/etc/resolv.conf:ro \ -v /var/lib/yggdrasil/data/pod-git/data/_data:/data \ -v /etc/timezone:/etc/timezone:ro \ @@ -29,24 +29,24 @@ ExecStart=/usr/bin/podman run \ -e USER_GID="1000" \ -e GITEA__database__DB_TYPE="postgres" \ -e GITEA__database__HOST="pod-database:5432" \ - -e GITEA__database__NAME="{{ services[service_name].database_name }}" \ - -e GITEA__database__USER="{{ services[service_name].database_user }}" \ - -e GITEA__database__PASSWD="{{ services[service_name].database_passwd }}" \ - -e GITEA__server__DOMAIN="{{ services[service_name].domain }}" \ + -e GITEA__database__NAME="{{ services[services_service_name].database_name }}" \ + -e GITEA__database__USER="{{ services[services_service_name].database_user }}" \ + -e GITEA__database__PASSWD="{{ services[services_service_name].database_passwd }}" \ + -e GITEA__server__DOMAIN="{{ services[services_service_name].domain }}" \ -e GITEA__server__ROOT_URL="https://%(DOMAIN)s/" \ -e GITEA__server__START_SSH_SERVER="true" \ - -e GITEA__server__SSH_PORT="{{ services[service_name].ssh_port }}" \ - -e GITEA__server__SSH_LISTEN_PORT="{{ services[service_name].ssh_port }}" \ + -e GITEA__server__SSH_PORT="{{ services[services_service_name].ssh_port }}" \ + -e GITEA__server__SSH_LISTEN_PORT="{{ services[services_service_name].ssh_port }}" \ -e GITEA__mailer__ENABLED="true" \ - -e GITEA__mailer__FROM="Gitea " \ + -e GITEA__mailer__FROM="Gitea " \ -e GITEA__mailer__MAILER_TYPE="smtp" \ - -e GITEA__mailer__HOST="{{ services[service_name].smtp_host }}" \ - -e GITEA__mailer__USER="{{ services[service_name].smtp_user }}" \ - -e GITEA__mailer__PASSWD="{{ services[service_name].smtp_passwd }}" \ + -e GITEA__mailer__HOST="{{ services[services_service_name].smtp_host }}" \ + -e GITEA__mailer__USER="{{ services[services_service_name].smtp_user }}" \ + -e GITEA__mailer__PASSWD="{{ services[services_service_name].smtp_passwd }}" \ -e GITEA__service__DISABLE_REGISTRATION="true" \ -e GITEA__service__ENABLE_NOTIFY_MAIL="true" \ --name=pod-git-gitea \ - docker.io/gitea/gitea:{{ versions.git.gitea }} + docker.io/gitea/gitea:{{ services_deploy_versions.git.gitea }} ExecStop=/usr/bin/podman stop --ignore --cidfile %t/container-git-gitea.ctr-id -t 10 ExecStopPost=/usr/bin/podman rm --ignore -f --cidfile %t/container-git-gitea.ctr-id PIDFile=%t/container-git-gitea.pid diff --git a/playbooks/filesystem/yggdrasil/var/lib/yggdrasil/home/pod-git/.config/systemd/user/pod-git.service.j2 b/plays/services/roles/deploy/git/templates/systemd/pod-git.service.j2 similarity index 100% rename from playbooks/filesystem/yggdrasil/var/lib/yggdrasil/home/pod-git/.config/systemd/user/pod-git.service.j2 rename to plays/services/roles/deploy/git/templates/systemd/pod-git.service.j2