Skip to content

Commit

Permalink
chore: update basic-service uninstall logic
Browse files Browse the repository at this point in the history
  • Loading branch information
O1ahmad committed Jan 6, 2025
1 parent b32c28d commit d88d001
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
destination_directory: /usr/local/bin
setup_mode: container
work_dir: /var/tmp
host_data_dir: /var/tmp

command:

Expand Down
75 changes: 62 additions & 13 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,71 @@
---
- name: Uninstall service container
community.docker.docker_container:
name: "{{ name }}"
# --- Storage Handlers ---
- name: Remove host data directory
ansible.builtin.file:
path: "{{ hostDataDir }}"
state: absent
purge_networks: true
listen: Container uninstall
when: hostDataDir is defined

- name: Remove generated service config files
become: true
- name: Remove generated config files
ansible.builtin.file:
path: "{{ work_dir }}/{{ item.value.destinationPath }}"
path: "{{ item.value.destinationPath }}"
state: absent
with_dict: "{{ config }}"
listen: Container uninstall

- name: Remove service data directory
become: true
- name: Remove config directories
ansible.builtin.file:
path: "{{ hostDataDir }}"
path: "{{ item.value.destinationPath | dirname }}"
state: absent
with_dict: "{{ config }}"

# --- Network Handlers ---
- name: Remove service ingress iptables rules
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_ports: "{{ ingress_list }}"
jump: ACCEPT
state: absent

# --- Binary Handlers ---
- name: Remove destination directory
ansible.builtin.file:
path: "{{ destination_directory }}"
state: absent

- name: Remove temporary binary file
ansible.builtin.file:
path: "/tmp/{{ binary_file_name }}"
state: absent

- name: Remove extracted files or moved binary
ansible.builtin.file:
path: "{{ destination_directory }}/{{ binary_file_name_override | default(binary_file_name) }}"
state: absent

# --- Systemd Handlers ---
- name: Remove the systemd unit file
ansible.builtin.include_role:
name: ansible-role-systemd
vars:
unit_config:
- name: "{{ name }}"
state: absent
enabled: false
perform_uninstall: true
when: setup_mode == 'systemd'

# --- Container Handlers ---
- name: Container uninstall
community.docker.docker_container:
name: "{{ name }}"
state: absent
when: setup_mode == 'container'

# --- Kubernetes Handlers ---
- name: Uninstall Helm release
kubernetes.core.helm:
name: "{{ name }}"
state: absent
listen: Container uninstall
release_namespace: "{{ helm_namespace }}"
when: setup_mode == 'k8s'
2 changes: 1 addition & 1 deletion tasks/container/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

- name: Determine service container volume list
ansible.builtin.set_fact:
volume_list: "{{ volume_list + [work_dir + item.value.destinationPath + ':' + item.value.destinationPath] }}"
volume_list: "{{ volume_list + [item.value.destinationPath | dirname + ':' + item.value.destinationPath | dirname ] }}"

Check warning on line 17 in tasks/container/setup.yml

View workflow job for this annotation

GitHub Actions / lint

17:121 [line-length] line too long (123 > 120 characters)

Check failure on line 17 in tasks/container/setup.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {{ volume_list + \[item.value.destinationPath | dirname + ':' + item.value.destinationPath | dirname ] }} -> {{ volume_list + \[item.value.destinationPath | dirname + ':' + item.value.destinationPath | dirname] }}
with_dict: "{{ config }}"

- name: Add data DIRs to container volume list
Expand Down
2 changes: 1 addition & 1 deletion tasks/systemd/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
systemd_environment_directive: "{{ systemd_environment_directive + ' ' + item.key + '=' + item.value }}"
with_dict: "{{ config_env }}"

- name: Set default Sysetmd unit configurations
- name: Set default Systemd unit configurations
ansible.builtin.set_fact:
default_unit_info:
Wants: network-online.target
Expand Down

0 comments on commit d88d001

Please sign in to comment.