refactor ♻️: Refactor Proxmox repository management
Some checks failed
ansible-lint / Ansible Lint (push) Failing after 6s
Gitleaks Scan / gitleaks (push) Successful in 4s
Markdown Lint / markdown-lint (push) Successful in 4s

Conditionally comment out and uncomment repositories, ensuring `apt update` is run only when necessary.
This commit is contained in:
2026-02-08 19:49:12 +01:00
parent f33d1563b7
commit c139461cef

View File

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