Manage Tumbleweed repositories with Ansible

Hi,

I’m a long-time Linux user (started out on Slackware 7.1 two and a half decades ago). I’ve used quite many distributions but I’m fairly new to Tumbleweed (after a false start a while back).

I’m currently fiddling with Tumbleweed and I must say I’m pleasantly surprised. I have a “vanilla” Tumbleweed/KDE installation in a VM and on a spare sandbox PC. Right now I’m writing an Ansible playbook to handle post-install configuration and fine-tuning, applying various hints and tweaks I can find either in the documentation or in various tutorials.

I have a problem with the repositories. For a start, I’d like to use the official (e. g. OSS, Non-OSS & Update) repositories as well as Packman Essentials and NVidia. So here’s what I have:

    - name: Configure OSS repository
      community.general.zypper_repository:
        name: oss
        repo: https://download.opensuse.org/tumbleweed/repo/oss/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Non-OSS repository
      community.general.zypper_repository:
        name: non-oss
        repo: https://download.opensuse.org/tumbleweed/repo/non-oss/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Updates repository
      community.general.zypper_repository:
        name: update
        repo: https://download.opensuse.org/update/tumbleweed/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Packman Essentials repository
      community.general.zypper_repository:
        name: packman-essentials
        repo: "https://ftp.gwdg.de/pub/linux/misc/packman/suse/\
               openSUSE_Tumbleweed/Essentials"
        state: present
        auto_import_keys: true
        enabled: true
        priority: 90

    - name: Configure NVidia repository
      community.general.zypper_repository:
        name: nvidia
        repo: https://download.nvidia.com/opensuse/tumbleweed
        state: present
        auto_import_keys: true
        enabled: true
        priority: 80

I also have a couple tasks that get rid of all unwanted *.repo files in /etc/zypp/repos.d:

    - name: Remove unneeded repositories
      ansible.builtin.file:
        path: "/etc/zypp/repos.d/{{item}}.repo"
        state: absent
      loop:
        - "download.opensuse.org-oss"
        - "download.opensuse.org-non-oss"
        - "download.opensuse.org-tumbleweed"
        - "repo-debug"
        - "repo-openh264"
        - "repo-source"
        - "NVIDIA:repo-non-free"
        - "openSUSE:repo-non-oss"
        - "openSUSE:repo-openh264"
        - "openSUSE:repo-oss-debug"
        - "openSUSE:repo-oss"
        - "openSUSE:repo-oss-source"
        - "openSUSE:update-tumbleweed"

    - name: Find installation media repository
      ansible.builtin.find:
        paths: /etc/zypp/repos.d/
        patterns: "openSUSE-*.repo"
      register: media_repo

    - name: Remove installation media repository
      ansible.builtin.file:
        path: "{{ media_repo.files[0].path }}"
        state: absent
      when: media_repo.matched > 0

The problem is that these files keep reappearing mysteriously. So my first question here would be: how can I keep these files from reappearing?

Cheers from the sunny South of France,

Niki

The Service:repo repositories are generated by the zypper repository services. Those services are added by the various openSUSE-repos-* packages (which may or may not be automatically installed depending on the hardware configuration). Either remove (and lock) these packages or disable the services they define. See man zypper:

zypper modifyservice -d ...
1 Like

Hmm … this probably will not work reliably. These packages unconditionally run zypper addservice ... on update and zypper will reset the disabled flag when “adding” the existing service. While updates of these packages are probably infrequent enough, they happen.

1 Like

I fiddled around some more and found the following solution to my problem:

    - name: Remove repository packages
      community.general.zypper:
        name: "openSUSE-repos-{{item}}"
        state: absent
      loop:
        - Leap
        - Leap-NVIDIA
        - MicroOS
        - MicroOS-NVIDIA
        - Slowroll
        - Slowroll-NVIDIA
        - Tumbleweed
        - Tumbleweed-NVIDIA

    - name: Add package locks
      ansible.builtin.copy:
        src: locks
        dest: /etc/zypp/locks
        owner: root
        group: root
        mode: 0644

    - name: Configure OSS repository
      community.general.zypper_repository:
        name: oss
        repo: https://download.opensuse.org/tumbleweed/repo/oss/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Non-OSS repository
      community.general.zypper_repository:
        name: non-oss
        repo: https://download.opensuse.org/tumbleweed/repo/non-oss/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Updates repository
      community.general.zypper_repository:
        name: update
        repo: https://download.opensuse.org/update/tumbleweed/
        state: present
        auto_import_keys: true
        enabled: true
        priority: 99

    - name: Configure Packman Essentials repository
      community.general.zypper_repository:
        name: packman-essentials
        repo: "https://ftp.gwdg.de/pub/linux/misc/packman/suse/\
               openSUSE_Tumbleweed/Essentials"
        state: present
        auto_import_keys: true
        enabled: true
        priority: 90

    - name: Configure NVidia repository
      community.general.zypper_repository:
        name: nvidia
        repo: https://download.nvidia.com/opensuse/tumbleweed
        state: present
        auto_import_keys: true
        enabled: true
        priority: 80

    - name: Remove unneeded repositories
      ansible.builtin.file:
        path: "/etc/zypp/repos.d/{{item}}.repo"
        state: absent
      loop:
        - "download.opensuse.org-oss"
        - "download.opensuse.org-non-oss"
        - "download.opensuse.org-tumbleweed"
        - "repo-debug"
        - "repo-openh264"
        - "repo-source"

    - name: Find installation media repository
      ansible.builtin.find:
        paths: /etc/zypp/repos.d/
        patterns: "openSUSE-*.repo"
      register: media_repo

    - name: Remove installation media repository
      ansible.builtin.file:
        path: "{{ media_repo.files[0].path }}"
        state: absent
      when: media_repo.matched > 0

Works perfectly for now.

Cheers,

Niki