Skip to content

Commit

Permalink
Delete lobby bots not present anymore
Browse files Browse the repository at this point in the history
This ensures the files belonging to bots removed from the configuration
are removed from lobby instances as well.
  • Loading branch information
Dunedan committed Mar 13, 2024
1 parent f47a731 commit 322bbdd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions roles/lobby_bots/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
54 changes: 54 additions & 0 deletions roles/lobby_bots/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,57 @@
loop: "{{ bots }}"
loop_control:
loop_var: bot

- name: Get list of custom systemd services
ansible.builtin.command:
cmd: "ls -1 /etc/systemd/system/"
changed_when: false
register: custom_systemd_services

- name: Check for lobby bot systemd service files
ansible.builtin.command:
cmd: "grep -i Pyrogenesis /etc/systemd/system/{{ service_file }}"
changed_when: false
failed_when: false
loop_control:
loop_var: service_file
loop: "{{ custom_systemd_services.stdout_lines }}"
register: pyrogenesis_systemd_services

- name: Stop outdated systemd services
ansible.builtin.systemd:
name: "{{ bot_name }}"
state: stopped
loop: >
{{ pyrogenesis_systemd_services.results | selectattr('rc', 'equalto', 0) |
map(attribute='service_file') | map('regex_replace', '^(.*)\.service$', '\1') }}
loop_control:
loop_var: bot_name
when: "bot_name not in bots | map(attribute='name')"

- name: Remove outdated systemd service files
ansible.builtin.file:
path: "/etc/systemd/system/{{ bot_name }}.service"
state: absent
loop: >
{{ pyrogenesis_systemd_services.results | selectattr('rc', 'equalto', 0) |
map(attribute='service_file') | map('regex_replace', '^(.*)\.service$', '\1') }}
loop_control:
loop_var: bot_name
when: "bot_name not in bots | map(attribute='name')"
notify: Reload systemd

- name: Check for existing lobby bot directories
ansible.builtin.command:
cmd: "ls -1 {{ lobby_bot_base_dir }}/"
changed_when: false
register: lobby_bot_dirs

- name: Remove outdated lobby bot directories
ansible.builtin.file:
path: "{{ lobby_bot_base_dir }}/{{ bot_name }}"
state: absent
loop: "{{ lobby_bot_dirs.stdout_lines }}"
loop_control:
loop_var: bot_name
when: "bot_name not in bots | map(attribute='name')"

0 comments on commit 322bbdd

Please sign in to comment.