role-service-proxmox_virtua.../tasks/repo-enable-free.yml

29 lines
1.9 KiB
YAML
Raw Normal View History

2025-04-03 02:36:50 +02:00
# SPDX-License-Identifier: MIT
- name: 'Check if pve-no-subscription repo is present'
register: 'pve_apt_repo_files_with_pve_free_repo'
changed_when: false
ansible.builtin.shell: |
pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-no-subscription")) | .path'
- name: 'If pve-no-subscription repo is present check if pve-no-subscription repo is enabled'
when: 'pve_apt_repo_files_with_pve_free_repo.stdout_lines | length > 0'
register: 'pve_apt_repo_files_free_repo_enabled_state'
changed_when: false
ansible.builtin.shell: |
pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.repositories[].Components | index("pve-no-subscription")) | .repositories[] | select(.Components | index("pve-no-subscription")) | .Enabled'
- name: 'If pve-no-subscription repo is disabled enable pve-no-subscription repo'
when: 'pve_apt_repo_files_free_repo_enabled_state.stdout == "0"'
loop_control:
loop_var: 'apt_repo_file'
label: 'Enable pve-no-subscription repo in {{ apt_repo_file | regex_replace(''"'', "''") }}'
loop: '{{ pve_apt_repo_files_with_pve_free_repo.stdout_lines }}'
ansible.builtin.shell: |
index_in_file="$(pvesh get /nodes/{{ inventory_hostname_short }}/apt/repositories --output-format=json | jq '.files[] | select(.path=={{ apt_repo_file }}) | .repositories | map(.Components | index("pve-no-subscription")) | index(0)')"
pvesh create /nodes/{{ inventory_hostname_short }}/apt/repositories -index "${index_in_file}" -path {{ apt_repo_file }} -enabled 'true'
- name: 'If pve-no-subscription repo is not present add pve-no-subscription repo'
when: 'pve_apt_repo_files_with_pve_free_repo.stdout_lines | length == 0'
ansible.builtin.shell: |
pvesh set /nodes/{{ inventory_hostname_short }}/apt/repositories -handle 'no-subscription'