saltstack-formulas / apache-formula

Set up and configure the Apache HTTP server

Home Page:http://docs.saltstack.com/en/latest/topics/development/conventions/formulas.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] apache.clean removed too much files, breaking installation after reinstall

danny-smit opened this issue · comments

Your setup

Formula commit hash / release tag

v1.2.2

Versions reports (master & minion)

Master:

Salt Version:
          Salt: 3007.0
 
Python Version:
        Python: 3.10.13 (main, Feb 19 2024, 03:31:20) [GCC 11.2.0]
 
Dependency Versions:
          cffi: 1.16.0
      cherrypy: unknown
      dateutil: 2.8.2
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.3
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.15.1
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.3.3
           ZMQ: 4.3.4
 
Salt Package Information:
  Package Type: onedir
 
System Versions:
          dist: centos 7.9.2009 Core
        locale: utf-8
       machine: x86_64
       release: 3.10.0-1160.114.2.el7.x86_64
        system: Linux
       version: CentOS Linux 7.9.2009 Core

Minion:

Salt Version:
          Salt: 3007.0
 
Python Version:
        Python: 3.10.13 (main, Feb 19 2024, 03:31:20) [GCC 11.2.0]
 
Dependency Versions:
          cffi: 1.16.0
      cherrypy: 18.8.0
      dateutil: 2.8.2
     docker-py: 7.0.0
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.3
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.7
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.5.2
        PyYAML: 6.0.1
         PyZMQ: 25.1.2
        relenv: 0.15.1
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 6.3.3
           ZMQ: 4.3.4
 
Salt Package Information:
  Package Type: onedir
 
System Versions:
          dist: debian 12.5 bookworm
        locale: utf-8
       machine: x86_64
       release: 6.1.0-18-amd64
        system: Linux
       version: Debian GNU/Linux 12.5 bookworm

Pillar / config used


Bug details

Describe the bug

When executing "apache.clean" the following actions are performed:

  • Disable the service
  • Remove the installed package
  • Wipe the configuration directory /etc/apache2 or /etc/httpd

On Debian based systems, the package "apache2" is uninstalled, but all module packages remain installed.

When installing apache2 afterwards, only the configuration files of that package are installed, but all module configuration files have been wiped and are not installed. This results to a broken apache installation

Steps to reproduce the bug

$ salt <host> state.apply apache,apache.modules
$ salt <host> state.apply clean
$ salt <host> state.apply apache,apache.modules

The third command breaks with errors like:

          ID: apache-config-modules-ssl-enable        
    Function: cmd.run                                 
        Name: a2enmod -f ssl                          
      Result: False                                   
     Comment: Command "a2enmod -f ssl" run            
     Started: 14:17:49.810351                         
    Duration: 31.092 ms                               
     Changes:                                         
              ----------                              
              pid:                                    
                  292010                              
              retcode:                                
                  1                                   
              stderr:                                 
                  ERROR: Module ssl does not exist!   
              stdout:                                 

Expected behaviour

The third command should successfully install and configure apache, just like the first command did.

Attempts to fix the bug

Additional context

Only a work-around:

$ salt <host> cmd.run "apt purge -y 'apache2*' 'libapache2-mod*' "
$ salt <host> state.apply apache,apache.modules

Alternative work around; implement a custom clean:

{%- from "apache/map.jinja" import apache without context %}

disable_apache:
  service.disabled:
    - name: {{ apache.service.name }}
    - enable: False

uninstall_apache:
  pkg.purged:
    - pkgs:
      - {{ apache.pkg.name }}

This works nicely, it purges the apache2 configuration, but does not touch the module files from other packages