Skip to content

Commit

Permalink
Add libvirt manifests cleanup tasks
Browse files Browse the repository at this point in the history
First draft to always get a clean manifests folder with all the effective .tf
and .cfg files, and no residual manifests from previous runs.

Fixes: #1
  • Loading branch information
rascasoft committed Oct 31, 2024
1 parent d0fce7e commit a6edd12
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tasks/libvirt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,58 @@
loop_control:
loop_var: tf_group_name

# Generate the files_to_keep list
- name: Create the list of .tf and .cfg files to keep
ansible.builtin.set_fact:
files_to_keep: []

- name: Add to files to keep list fixed resources files
ansible.builtin.set_fact:
files_to_keep: "{{ files_to_keep + [ tf_config_dir + '/' + item + '.tf' ] }}"

Check warning on line 66 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {{ files_to_keep + [ tf_config_dir + '/' + item + '.tf' ] }} -> {{ files_to_keep + \[tf_config_dir + '/' + item + '.tf'] }}

Check failure on line 66 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

yaml[indentation]

Wrong indentation: expected 4 but found 5
with_items:
- 'provider'
- 'networks'
- 'pools'
- 'volumes'
- 'cloud_init'

- name: Add to files to keep list dynamic cloud_init.cfg files
ansible.builtin.set_fact:
files_to_keep: "{{ files_to_keep + [ tf_config_dir + '/cloud_init_' + item.name + '.cfg' ] }}"

Check warning on line 76 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {{ files_to_keep + [ tf_config_dir + '/cloud_init_' + item.name + '.cfg' ] }} -> {{ files_to_keep + \[tf_config_dir + '/cloud_init_' + item.name + '.cfg'] }}

Check failure on line 76 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

yaml[indentation]

Wrong indentation: expected 4 but found 5
with_items:
- "{{ tf_libvirt_cloud_inits }}"

- name: Add to files to keep list dynamic .vms.tf files
ansible.builtin.set_fact:
files_to_keep: "{{ files_to_keep + [ tf_config_dir + '/' + item + '.vms.tf' ] }}"

Check warning on line 82 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {{ files_to_keep + [ tf_config_dir + '/' + item + '.vms.tf' ] }} -> {{ files_to_keep + \[tf_config_dir + '/' + item + '.vms.tf'] }}
with_items:
- "{{ tf_libvirt_vms_groups }}"

- name: Get the stats (including absolute paths) of the remote files
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ files_to_keep }}"
register: files_to_keep_stats

- name: Create a list of files to keep with absolute paths

Check failure on line 92 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

fqcn[action-core]

Use FQCN for builtin module actions (set_fact).
set_fact:
files_to_keep_full_path: "{{ files_to_keep_full_path | default([]) + [ item.stat.path ] }}"

Check warning on line 94 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

jinja[spacing]

Jinja2 spacing could be improved: {{ files_to_keep_full_path | default([]) + [ item.stat.path ] }} -> {{ files_to_keep_full_path | default([]) + \[item.stat.path] }}
loop: "{{ files_to_keep_stats.results }}"

# Generate the list of all files
- name: Find all .tf and .cfg files in tf_config_dir

Check failure on line 98 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

fqcn[action-core]

Use FQCN for builtin module actions (find).
find:
paths: "{{ tf_config_dir }}"
patterns: "*.tf,*.cfg"
register: all_files

- name: Delete files not to keep

Check failure on line 104 in tasks/libvirt.yml

View workflow job for this annotation

GitHub Actions / lint

fqcn[action-core]

Use FQCN for builtin module actions (file).
file:
path: "{{ item.path }}"
state: absent
loop: "{{ all_files.files }}"
when: item.path not in files_to_keep_full_path

- name: Display a reminder for sourcing variables
ansible.builtin.debug:
msg:
Expand Down

0 comments on commit a6edd12

Please sign in to comment.