Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update logic based on latest round of manual testing #23

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 70 additions & 61 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,70 +1,79 @@
---
- name: Uninstall Service
# --- Storage Handlers ---
- name: Remove host data directory
listen: Uninstall Service
block:
# --- Storage Handlers ---
- name: Remove host data directory
ansible.builtin.file:
path: "{{ host_data_dir }}"
state: absent
when: host_data_dir != "/var/tmp"
ansible.builtin.file:
path: "{{ host_data_dir }}"
state: absent
when:
- host_data_dir is defined
- host_data_dir != "/var/tmp"

- name: Remove config directories
ansible.builtin.file:
path: "{{ host_data_dir + item.value.destinationPath | dirname }}"
state: absent
with_dict: "{{ config }}"

- name: Remove config directories
ansible.builtin.file:
path: "{{ item.value.hostPath | dirname }}"
state: absent
with_dict: "{{ data_dirs }}"
- name: Remove configuration directories
listen: Uninstall Service
ansible.builtin.file:
path: "{{ host_data_dir + item.value.destinationPath | dirname }}"
state: absent
loop: "{{ config | dict2items }}"
loop_control:
label: "{{ item.key }}"
when: config is defined and config | length > 0

# --- Network Handlers ---
- name: Remove service ingress iptables rules
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_ports: "{{ ingress_list }}"
jump: ACCEPT
state: absent
- name: Remove data directories
listen: Uninstall Service
become: true
ansible.builtin.file:
path: "{{ item.value.hostPath }}"
state: absent
loop: "{{ data_dirs | dict2items }}"
loop_control:
label: "{{ item.key }}"
when: data_dirs is defined and data_dirs | length > 0

# --- Systemd Handlers ---
- name: Remove temporary binary file
ansible.builtin.file:
path: "/tmp/{{ binary_file_name }}"
state: absent
when: setup_mode == 'systemd'
# --- Network Handlers ---
- name: Remove service ingress iptables rules
listen: Uninstall Service
ansible.builtin.iptables:
chain: INPUT
protocol: tcp
destination_ports: "{{ ingress_list }}"
jump: ACCEPT
state: absent
when: ingress_list is defined and ingress_list | length > 0

- 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'
# --- Systemd Handlers ---
- name: Remove temporary binary file
listen: Uninstall Service
ansible.builtin.file:
path: "/tmp/{{ binary_file_name }}"
state: absent
when:
- setup_mode == 'systemd'
- binary_file_name is defined

- 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 extracted files or moved binary
listen: Uninstall Service
ansible.builtin.file:
path: "{{ destination_directory }}/{{ binary_file_name_override | default(binary_file_name) }}"
state: absent
when:
- setup_mode == 'systemd'
- binary_file_name is defined
- destination_directory is defined

# --- Container Handlers ---
- name: Container uninstall
community.docker.docker_container:
name: "{{ name }}"
state: absent
when: setup_mode == 'container'
# --- Container Handlers ---
- name: Container uninstall
listen: Uninstall Service
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'
# --- Kubernetes Handlers ---
- name: Uninstall Helm release
listen: Uninstall Service
kubernetes.core.helm:
name: "{{ name }}"
state: absent
release_namespace: "{{ helm_namespace }}"
when: setup_mode == 'k8s'
12 changes: 9 additions & 3 deletions tasks/common/storage-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
ansible.builtin.file:
path: "{{ host_data_dir }}"
state: directory
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
owner: "{{ user | default(ansible_user) }}"
group: "{{ group | default(user) | default(ansible_user) }}"
mode: "0755"

- name: Ensure existence of config dir
become: true
ansible.builtin.file:
path: "{{ host_data_dir + item.value.destinationPath | dirname }}"
state: directory
owner: "{{ user | default(ansible_user) }}"
group: "{{ group | default(user) | default(ansible_user) }}"
mode: "0755"
with_dict: "{{ config }}"

Expand All @@ -23,12 +25,16 @@
dest: "{{ host_data_dir + item.value.destinationPath }}"
mode: "{{ item.value.mode | default(644) }}"
src: "{{ item.value.sourcePath | default(omit) }}"
owner: "{{ user | default(ansible_user) }}"
group: "{{ group | default(user) | default(ansible_user) }}"
with_dict: "{{ config }}"

- name: Ensure existence of host data dirs
become: true
ansible.builtin.file:
path: "{{ item.value.hostPath | dirname }}"
path: "{{ item.value.hostPath }}"
state: directory
mode: "0755"
owner: "{{ user | default(ansible_user) }}"
group: "{{ group | default(user) | default(ansible_user) }}"
with_dict: "{{ data_dirs }}"
38 changes: 26 additions & 12 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
---
- name: Uninstall provisioned service components
when: uninstall|bool
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
- name: Flush handlers to ensure uninstall is completed
ansible.builtin.meta: flush_handlers

- name: Setup service infrastructure topology
when: setup_mode is defined
ansible.builtin.include_tasks: "{{ setup_mode }}/setup.yml"
- name: Remove systemd artifacts
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: Manage networking and IP tables setup
when: setup_iptables|bool
ansible.builtin.include_tasks: common/network-setup.yml
- name: Setup service components
when: uninstall is not defined or not uninstall | bool
block:
- name: Manage storage/data setup
ansible.builtin.include_tasks: common/storage-setup.yml

- name: Setup service infrastructure topology
when: setup_mode is defined
ansible.builtin.include_tasks: "{{ setup_mode }}/setup.yml"

- name: Manage networking and IP tables setup
when: setup_iptables | bool
ansible.builtin.include_tasks: common/network-setup.yml
Loading