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

[ansible/ovos] Make sure directory exists priot backup #242

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
12 changes: 11 additions & 1 deletion ansible/roles/ovos_installer/tasks/ovos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
tags:
- uninstall

- name: Check if directory to backup exists
ansible.builtin.stat:
path: "{{ ovos_directories_backup }}"
register: _ovos_installer_directory_exists
when: ovos_installer_cleaning | bool
tags:
- uninstall

Comment on lines +17 to +24
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix incorrect usage of ansible.builtin.stat with multiple paths

The ansible.builtin.stat module expects a single path string, but ovos_directories_backup is a list of paths. This will cause the task to fail.

Consider using a loop to check each directory separately:

 - name: Check if directory to backup exists
   ansible.builtin.stat:
-    path: "{{ ovos_directories_backup }}"
+    path: "{{ item }}"
   register: _ovos_installer_directory_exists
+  loop: "{{ ovos_directories_backup }}"
   when: ovos_installer_cleaning | bool
   tags:
     - uninstall

Note: You'll need to adjust the backup task's condition to check the existence of all directories using the registered results.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Check if directory to backup exists
ansible.builtin.stat:
path: "{{ ovos_directories_backup }}"
register: _ovos_installer_directory_exists
when: ovos_installer_cleaning | bool
tags:
- uninstall
- name: Check if directory to backup exists
ansible.builtin.stat:
path: "{{ item }}"
register: _ovos_installer_directory_exists
loop: "{{ ovos_directories_backup }}"
when: ovos_installer_cleaning | bool
tags:
- uninstall

- name: Backup existing configurations before uninstall
community.general.archive:
path: "{{ ovos_directories_backup }}"
Expand All @@ -23,7 +31,9 @@
mode: "0755"
format: gz
force_archive: true
when: ovos_installer_cleaning | bool
when:
- ovos_installer_cleaning | bool
- _ovos_installer_directory_exists.stat.exists | bool
goldyfruit marked this conversation as resolved.
Show resolved Hide resolved
tags:
- uninstall

Expand Down
Loading