saltstack-formulas / php-formula

http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html
Other
57 stars 231 forks source link

[BUG] salt <minion> state.sls php.modules or salt <minion> state.sls php.fpm failed by duplicates packages. #241

Open Aurely9n opened 7 months ago

Aurely9n commented 7 months ago

Your setup

Formula commit hash / release tag

I'm using php-formula 9c69a4e. the last one on master branch

Versions reports (master & minion)

Master :

version: Debian GNU/Linux 12 bookworm Salt Version 3006.6

Minion server:

version: Debian GNU/Linux 12 bookworm Salt Version: 3006.7

Pillar / config used

php:
  lookup:
    pkgs:
      gettext: php-gettext
  use_external_repo: true
  external_repo_name: 'ondrej/php'
  version:
    - '7.4'
    - '8.1'
    - '8.2'
    - '8.3'
  alternatives_version: '7.4'
  fpm:
    ....
  modules:
      - cli
      - fpm
      - apcu
      - bz2
      - curl
      - gd
      - intl
      - mbstring
      - mysql
      - xml
      - zip  

Bug details

Describe the bug

On launch salt {minion} state.sls php.modules (php.apcu) and/or salt {minion} php.fpm, they both failed by trying to install duplicate package.

Steps to reproduce the bug

salt {minion} state.sls php.modules produce only this error :

ID: php_install_apcu
Function: pkg.installed
    Name: apcu
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/state.py", line 2424, in call
              ret = self.states[cdata["full"]](
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in __call__
              ret = self.loader.run(run_func, *args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
              return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
              return _func_or_method(*args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1293, in wrapper
              return f(*args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pkg.py", line 1704, in installed
              result = _find_install_targets(
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pkg.py", line 585, in _find_install_targets
              desired = _repack_pkgs(pkgs, normalize=normalize)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pkg_resource.py", line 38, in _repack_pkgs
              raise SaltInvocationError(
          salt.exceptions.SaltInvocationError: You are passing a list of packages that contains duplicated packages names: ['php-apcu-bc', 'php-apcu-bc', 'php-apcu-bc', 'php-apcu-bc']. This cannot be processed. In case you are targeting different versions of the same package, please target them individually
 Started: 09:01:05.683666
Duration: 9.847 ms
 Changes:

salt {minion} state.sls php.fpm produce this error :

ID: php_install_fpm
Function: pkg.installed
    Name: fpm
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/state.py", line 2424, in call
              ret = self.states[cdata["full"]](
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 159, in __call__
              ret = self.loader.run(run_func, *args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1245, in run
              return self._last_context.run(self._run_as, _func_or_method, *args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1260, in _run_as
              return _func_or_method(*args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/loader/lazy.py", line 1293, in wrapper
              return f(*args, **kwargs)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pkg.py", line 1704, in installed
              result = _find_install_targets(
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/pkg.py", line 585, in _find_install_targets
              desired = _repack_pkgs(pkgs, normalize=normalize)
            File "/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/pkg_resource.py", line 38, in _repack_pkgs
              raise SaltInvocationError(
          salt.exceptions.SaltInvocationError: You are passing a list of packages that contains duplicated packages names: ['php7.4-fpm', 'php7.4-fpm', 'php8.1-fpm', 'php8.2-fpm', 'php8.3-fpm']. This cannot be processed. In case you are targeting different versions of the same package, please target them individually
 Started: 09:04:42.869406
Duration: 24.721 ms
 Changes:

Expected behaviour

This 2 errors didn't appear when the same pillar is launched on older sminions server (salt-minion 3002.9+ds-1). There is not any duplicates packages in queue.

Attempts to fix the bug

In installed.jinja, i've write line 23:

  {% if other_version_str != first_version %}
    {% do pkgs.append(pkg.replace(first_version, other_version_str)) %}
  {% endif %}

and line 36:

  {% if other_version_str != first_version %}
    {% do pkgs.append(pkginfo.replace(first_version, other_version_str)) %}
  {% endif %}

And it seems to correct salt state.sls php.fpm error. But i didn't yet identified the problem with php.apcu or php.modules state.

Additional context

Thanks

gruizonestic commented 2 months ago

Hello there! I've found a temporal solution for this problem. In the installed.jinja file, after looping through all the different versions to create the pkgs and specials arrays, you can use the unique Jinja filter to remove duplicates.

line 39, add this piece of code.

{% set pkgs = pkgs | unique %}
{% set specials = specials | unique %}

After applying the fix, no more duplicate packages errors appear while calling php.modules, php.ini or php.fpm.