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 191f20c
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 34 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
98 changes: 77 additions & 21 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,78 @@
---
- name: Uninstall service container
community.docker.docker_container:
name: "{{ name }}"
state: absent
purge_networks: true
listen: Container uninstall

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

- name: Remove service data directory
become: true
ansible.builtin.file:
path: "{{ hostDataDir }}"
state: absent
listen: Container uninstall
- name: Uninstall Service
listen: Uninstall Service
block:
# --- Storage Handlers ---
- name: Remove host data directory
ansible.builtin.file:
path: "{{ hostDataDir }}"
state: absent
when: hostDataDir is defined

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

# --- Systemd Handlers ---
- name: Remove destination directory
ansible.builtin.file:
path: "{{ destination_directory }}"
state: absent
when: setup_mode == 'systemd'

- name: Remove temporary binary file
ansible.builtin.file:
path: "/tmp/{{ binary_file_name }}"
state: absent
when: setup_mode == 'systemd'

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

- 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'

- name: Remove generated config files
ansible.builtin.file:
path: "{{ item.value.destinationPath }}"
state: absent
with_dict: "{{ config }}"
when: setup_mode == 'systemd'

- name: Remove config directories
ansible.builtin.file:
path: "{{ item.value.destinationPath | dirname }}"
state: absent
with_dict: "{{ config }}"
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
release_namespace: "{{ helm_namespace }}"
when: setup_mode == 'k8s'
13 changes: 1 addition & 12 deletions tasks/container/setup.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
---
- name: Uninstall provisioned container components
when: uninstall|bool
block:
- name: Broadcast uninstall signal
ansible.builtin.command: /bin/true
notify: Container uninstall
changed_when: true
always:
- name: End play following uninstallation
ansible.builtin.meta: end_play

# Compile container resource lists

- 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 6 in tasks/container/setup.yml

View workflow job for this annotation

GitHub Actions / lint

6:121 [line-length] line too long (122 > 120 characters)
with_dict: "{{ config }}"

- name: Add data DIRs to container volume list
Expand Down
11 changes: 11 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
---
- name: Uninstall provisioned service components
when: uninstall|bool
block:
- name: Broadcast uninstall signal
ansible.builtin.command: /bin/true
notify: Uninstall Service
changed_when: true
always:
- name: End play following uninstallation
ansible.builtin.meta: end_play

- name: Manage storage/data setup
ansible.builtin.include_tasks: common/storage-setup.yml

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 191f20c

Please sign in to comment.