refactor: organize ansible stuff
Deploy bin / deploy (push) Successful in 3s
Deploy, build and restart MASTER / deploy (push) Successful in 5s
Deploy agebd python package / deploy (push) Successful in 2s

This commit is contained in:
Benjamin Labrecque
2026-07-07 13:47:54 +02:00
parent 577610848a
commit bf2fe80358
12 changed files with 66 additions and 81 deletions
+1 -1
View File
@@ -15,4 +15,4 @@ jobs:
- name: Restart master service
run: |
ansible-playbook ansible/add-new-service.yml -i hosts.yml
ansible-playbook ansible/playbooks/add-new-service.yml -i hosts.yml
-5
View File
@@ -1,5 +0,0 @@
# TODO: Create venv and install ansible? That way not dependent on ansible
# being installed on machine.
- name: Restart Master IOC
import_playbook: plays/restart-master-ioc.yml
+8
View File
@@ -0,0 +1,8 @@
# TODO: Create venv and install ansible? That way not dependent on ansible
# being installed on machine.
- name: Install and Restart Master IOC
import_playbook: ../plays/ioc/ioc-install-and-restart-master.yml
- name: Deploy and Restart Master Service
import_playbook: ../plays/service/service-deploy-and-restart-master.yml
@@ -1,4 +1,4 @@
- name: Dynamic HLA Microservices Deployer
- name: Deploy and Restart Modified Services
hosts: localhost
gather_facts: yes
@@ -8,14 +8,14 @@
agebd_env: "dev"
tasks:
# 1. Fail early if no services were modified
# Fail early if no services were modified
- name: Check if there are services to deploy
ansible.builtin.meta: end_play
when: changed_services_raw | trim == ""
# 2. Main Loop: Loop through the list of modified service names
- name: Deploy Modified Services
include_tasks: plays/service-deploy.yml
# Main Loop: Loop through the list of modified service names
- name: Deploy and Restart Modified Services
include_tasks: plays/service/service-deploy-and-restart.yml
loop: "{{ changed_services_raw.split() }}"
loop_control:
loop_var: service_dir_name
-27
View File
@@ -1,27 +0,0 @@
- name: Start an IOC
# TODO: env
hosts: sls-vserv-bd-01-dev
gather_facts: false
#TODO: docs?
# For the git clone and git push commands to work smoothly inside this playbook,
# ensure your shell environment is passing your SSH key. Run ssh-add -l on your
# terminal before firing up ansible-playbook.
# TODO
# If the machine executing this playbook doesn't have a global Git user configured,
# the git commit task will fail. You can explicitly bypass this by adding environment
# variables directly to the commit task if needed:
# environment:
# GIT_COMMITTER_NAME: "Ansible Provisioner"
# GIT_COMMITTER_EMAIL: "your-email@psi.ch"
# GIT_AUTHOR_NAME: "Ansible Provisioner"
# GIT_AUTHOR_EMAIL: "your-email@psi.ch"
tasks:
- name: Start IOC
# TODO:
# sudo shellbox status
# sudo shellbox reload
# sudo shellbox status
# sudo shellbox start XXXXXXX
@@ -0,0 +1,4 @@
- name: Install and Restart Master IOC
vars:
service_dir_name: 000-master
import_playbook: ioc-install-and-restart.yml
-6
View File
@@ -1,6 +0,0 @@
- name: Restart Master IOC
vars:
service_dir_name: 000-master
import_playbook: ioc-install-and-restart.yml
# TODO: restart systemd master service?
-37
View File
@@ -1,37 +0,0 @@
- name: "[{{ service_dir_name }}] Define service specific paths and names"
ansible.builtin.set_fact:
# 1. The literal directory name on disk (e.g., "000-master")
svc_current_dir: "/sls/bd/hla/{{ agebd_env }}/services/{{ service_dir_name }}/current"
# 2. Extract logical service name by dropping the first 4 characters and converting to UPPERCASE (e.g., "MASTER")
service_unit_name: "AGEBD-SERVICE-{{ service_dir_name[4:] | upper }}.service"
- name: "[{{ service_dir_name }}] Ensure target directory structure exists"
ansible.builtin.file:
path: "{{ svc_current_dir }}"
state: directory
mode: '0755'
- name: "[{{ service_dir_name }}] Sync service deployment files"
ansible.builtin.copy:
src: "{{ playbook_dir }}/../services/{{ service_dir_name }}/current/"
dest: "{{ svc_current_dir }}/"
mode: 'preserve'
- name: "[{{ service_dir_name }}] Substitute environment variable inline"
ansible.builtin.replace:
path: "{{ svc_current_dir }}/systemd/{{ service_unit_name }}"
regexp: '\{\{\s*agebd_env\s*\}\}'
replace: "{{ agebd_env }}"
- name: "[{{ service_dir_name }}] Restart Systemd Service using Relative Paths"
ansible.builtin.shell: |
# 1. Tell systemd to link the service file into its registry relatively
systemctl --user link "./{{ service_unit_name }}"
systemctl --user daemon-reload
systemctl --user enable "{{ service_unit_name }}"
systemctl --user restart "{{ service_unit_name }}"
args:
chdir: "{{ svc_current_dir }}/systemd"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ ansible_effective_user_id }}"
@@ -0,0 +1,4 @@
- name: Deploy and Restart Master Service
vars:
service_dir_name: 000-master
import_playbook: service-deploy-and-restart.yml
@@ -0,0 +1,44 @@
- name: Deploy and Restart Service
# TODO: dev/prod
hosts: sls-vserv-bd-hla01-dev
connection: local
gather_facts: false
tasks:
- name: "[{{ service_dir_name }}] Define service specific paths and names"
ansible.builtin.set_fact:
# 1. The literal directory name on disk (e.g., "000-master")
svc_current_dir: "/sls/bd/hla/{{ agebd_env }}/services/{{ service_dir_name }}/current"
# 2. Extract logical service name by dropping the first 4 characters and converting to UPPERCASE (e.g., "MASTER")
service_unit_name: "AGEBD-SERVICE-{{ service_dir_name[4:] | upper }}.service"
- name: "[{{ service_dir_name }}] Ensure target directory structure exists"
ansible.builtin.file:
path: "{{ svc_current_dir }}"
state: directory
mode: '0755'
- name: "[{{ service_dir_name }}] Sync service deployment files"
ansible.builtin.copy:
src: "{{ playbook_dir }}/../services/{{ service_dir_name }}/current/"
dest: "{{ svc_current_dir }}/"
mode: 'preserve'
- name: "[{{ service_dir_name }}] Substitute environment variable inline"
ansible.builtin.replace:
path: "{{ svc_current_dir }}/systemd/{{ service_unit_name }}"
regexp: '\{\{\s*agebd_env\s*\}\}'
replace: "{{ agebd_env }}"
- name: "[{{ service_dir_name }}] Restart Systemd Service using Relative Paths"
ansible.builtin.shell: |
# 1. Tell systemd to link the service file into its registry relatively
systemctl --user link "./{{ service_unit_name }}"
systemctl --user daemon-reload
systemctl --user enable "{{ service_unit_name }}"
systemctl --user restart "{{ service_unit_name }}"
args:
chdir: "{{ svc_current_dir }}/systemd"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ ansible_effective_user_id }}"