refactor ♻️: Refactor Proxmox repository management #5

Merged
Jose merged 5 commits from dev into main 2026-02-08 20:09:56 +01:00
Showing only changes of commit c139461cef - Show all commits

View File

@@ -1,18 +1,49 @@
---
- name: repos | Comment out Proxmox enterprise repo lines
ansible.builtin.replace:
path: /etc/apt/sources.list.d/pve-enterprise.list
regexp: '^(deb\s+)'
replace: '# \1'
when: ansible.builtin.stat(path='/etc/apt/sources.list.d/pve-enterprise.list').stat.exists
notify: apt update
- name: repos | Manage Proxmox repositories
block:
- name: repos | Enable Proxmox no-subscription repo
ansible.builtin.copy:
dest: /etc/apt/sources.list.d/pve-no-subscription.list
owner: root
group: root
mode: "0644"
content: |
deb http://download.proxmox.com/debian/pve {{ ansible_distribution_release }} pve-no-subscription
notify: apt update
#Proxmox enterprise repo
- name: repos | Check for Proxmox enterprise repo file
ansible.builtin.stat:
Review

[Lines 6-8] [Score: 2] Const declarations are generally preferred for variable declaration. It makes the code more explicit and easier to understand, especially when dealing with complex data structures or multiple variables with the same type. Here, const repo_path could be used instead of var.

[Lines 6-8] [Score: 2] Const declarations are generally preferred for variable declaration. It makes the code more explicit and easier to understand, especially when dealing with complex data structures or multiple variables with the same type. Here, `const repo_path` could be used instead of `var`.
path: /etc/apt/sources.list.d/pve-enterprise.list
register: pve_enterprise_repo
- name: repos | Comment out Proxmox enterprise repo lines
ansible.builtin.replace:
path: /etc/apt/sources.list.d/pve-enterprise.list
regexp: '^(deb\s+)'
replace: '# \1'
Review

[Score: 2] Incorrect syntax due to missing semicolon. It can lead to unexpected behavior or errors.

[Score: 2] Incorrect syntax due to missing semicolon. It can lead to unexpected behavior or errors.
when: pve_enterprise_repo.stat.exists
register: enterprise_changed
#Proxmox no-subscription repo
- name: repos | Check for pve-install-repo.list
ansible.builtin.stat:
path: /etc/apt/sources.list.d/pve-install-repo.list
register: pve_install_repo
- name: repos | Uncomment Proxmox no-subscription repo if present
ansible.builtin.replace:
path: /etc/apt/sources.list.d/pve-install-repo.list
regexp: '^#\s*(deb\s+http://download\.proxmox\.com/debian/pve\s+{{ ansible_distribution_release }}\s+pve-no-subscription)'
replace: '\1'
when: pve_install_repo.stat.exists
register: no_sub_uncommented
- name: repos | Add Proxmox no-subscription repo if missing
Review

[Lines 34-35] [Score: 2] Use a more descriptive regex pattern for better readability. For example, ^#\s*deb\s+{{ repo_path }}\s+[a-zA-Z]+s+\s+pve-no-subscription

[Lines 34-35] [Score: 2] Use a more descriptive regex pattern for better readability. For example, `^#\s*deb\s+{{ repo_path }}\s+[a-zA-Z]+s+\s+pve-no-subscription`
ansible.builtin.lineinfile:
path: /etc/apt/sources.list.d/pve-install-repo.list
regexp: '^deb\s+http://download\.proxmox\.com/debian/pve\s+{{ ansible_distribution_release }}\s+pve-no-subscription$'
line: "deb http://download.proxmox.com/debian/pve {{ ansible_distribution_release }} pve-no-subscription"
state: present
insertafter: EOF
when: pve_install_repo.stat.exists
register: no_sub_added
Review

[Lines 42-43] [Score: 2] Use a more descriptive regex pattern for better readability. For example, ^deb\s*{{ repo_path }}\s+[a-zA-Z]+s+\s+pve-no-subscription$

[Lines 42-43] [Score: 2] Use a more descriptive regex pattern for better readability. For example, `^deb\s*{{ repo_path }}\s+[a-zA-Z]+s+\s+pve-no-subscription$`
# Notify Run apt update only once if any of the above tasks changed something
notify:
- Run apt update
# Trigger only if any changes occurred
when: enterprise_changed.changed or no_sub_uncommented.changed or no_sub_added.changed