saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

[BUG] State `pkgrepo.absent` and `pkg.del_repo` module are unable to delete repositories previously created with `pkgrepo.managed` #61602

Closed javierbertoli closed 1 year ago

javierbertoli commented 2 years ago

Description I think this is a follow-up of #51656.

I hit this is issue today while working on the docker-formula, using salt version 3004:

Setup

Steps to Reproduce the behavior

  1. create the repository with the following sls file
       docker-software-package-repo-managed:
         pkgrepo.managed:
           - comments: ['installed by salt']
           - enabled: 1
           - file: /etc/apt/sources.list.d/docker.list
           - gpgcheck: 1
           - name: deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable
           - humanname: Debian Bullseye Docker Package Repository
           - refresh: True
  2. After running the state, the file /etc/apt/sources.list.d/docker.list will be created with the following content
    deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable
  3. The following state is unable to delete the repo
       docker-software-package-repo-absent:
         pkgrepo.absent:
           - name: deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable

As I understand the state is a wrapper of pkg.del_repo, I tried it too, to confirm the issue:

a. pkg.get_repo is able to find the repository correctly:

# salt-call --local pkg.get_repo 'deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable'
local:
    ----------
    architectures:
        - amd64
    comps:
        - stable
    disabled:
        False
    dist:
        bullseye
    file:
        /etc/apt/sources.list.d/docker.list
    line:
        deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable
    type:
        deb
    uri:
        https://download.docker.com/linux/debian

b. del_repo is unable to find the entry and delete it

# salt-call --local pkg.del_repo 'deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable'
Error running 'pkg.del_repo': Repo deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg arch=amd64] https://download.docker.com/linux/debian bullseye stable doesn't exist in the sources.list(s)

Expected behavior Both the state pkgrepo.absent and the module pkg.del_repo should be able to delete a repository that exists.

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.) ``` Salt Version: Salt: 3004 Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 2.8.1 docker-py: 4.1.0 gitdb: Not Installed gitpython: Not Installed Jinja2: 2.11.3 libgit2: Not Installed M2Crypto: Not Installed Mako: Not Installed msgpack: 1.0.0 msgpack-pure: Not Installed mysql-python: Not Installed pycparser: Not Installed pycrypto: Not Installed pycryptodome: 3.9.7 pygit2: Not Installed Python: 3.9.2 (default, Feb 28 2021, 17:03:44) python-gnupg: Not Installed PyYAML: 5.3.1 PyZMQ: 20.0.0 smmap: Not Installed timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.4 System Versions: dist: debian 11 bullseye locale: utf-8 machine: x86_64 release: 5.10.0-10-amd64 system: Linux version: Debian GNU/Linux 11 bullseye ```
garethgreenaway commented 2 years ago

@javierbertoli There were quite a few changes and fixes that went into the 3005.1 release for the pkgrepo module, Are you able to upgrade and see if the issues you're seeing are resolved? Thanks!

garethgreenaway commented 1 year ago

Closing this one out due to lack of activity, if the issue persists please feel free to open a new issue. Thanks!

votdev commented 1 year ago

This bug still exists in 3005.1.

remove_apt_sources_list_security_0:
  module.run:
    - pkg.del_repo:
      - repo: "deb-src [signed-by=/etc/apt/trusted.gpg.d/debian-archive-bullseye-security-automatic.gpg] http://security.debian.org/debian-security bullseye-security main contrib non-free"
[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 2276, in call
    ret = self.states[cdata["full"]](
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1276, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/module.py", line 394, in run
    return _run(**kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/module.py", line 449, in _run
    func_ret = _call_function(
  File "/usr/lib/python3/dist-packages/salt/states/module.py", line 495, in _call_function
    mret = salt.utils.functools.call_function(__salt__[name], *func_args, **func_kwargs)
  File "/usr/lib/python3/dist-packages/salt/utils/functools.py", line 174, in call_function
    return salt_function(*function_args, **function_kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 149, in __call__
    return self.loader.run(run_func, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1228, in run
    return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/loader/lazy.py", line 1243, in _run_as
    return _func_or_method(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/modules/aptpkg.py", line 2138, in del_repo
    raise CommandExecutionError(
salt.exceptions.CommandExecutionError: Repo deb-src [signed-by=/etc/apt/trusted.gpg.d/debian-archive-bullseye-security-automatic.gpg] http://security.debian.org/debian-security bullseye-security main contrib non-free doesn't exist in the sources.list(s)