Remove Salt configuration

If you delete something from a file, it won’t be removed from the server, in most cases. To remove it, after you deploy:

Delete a file

Run, for example:

./run.py 'docs' file.remove /path/to/file-to-remove

Delete a line from a file

Run, for example:

./run.py 'docs' cmd.run "sed --in-place '/text to match/d' /path/to/file"

Delete a user

  1. Move any files from the user’s home directory and change their ownership

  2. Add a temporary state, for example:

    analysis:
      user.absent:
        - purge: True
    
  3. Run the temporary state, for example:

    ./run.py 'mytarget' state.sls_id analysis kingfisher
    
  4. Remove the temporary state

Note

The purge option will delete all of the user’s files.

Delete a cron job

  1. Change cron.present to cron.absent in the Salt state

  2. Deploy the server

  3. Delete the Salt state

Delete a service

Stop and disable the service. For example:

./run.py 'mytarget' service.stop myservice
./run.py 'mytarget' service.disable myservice

Delete any configuration files added by the service (for example, under sites-available and sites-enabled, for Apache).

Note

There is an open issue to make removing services easier.

Delete a package

Remove a package and its configuration files, and remove any of its dependencies that are no longer needed.

To scrub packages, for example:

./run.py 'mytarget' pkg.purge libapache2-mod-proxy-uwsgi,uwsgi-plugin-python3,uwsgi
./run.py 'mytarget' pkg.autoremove list_only=True
./run.py 'mytarget' pkg.autoremove purge=True

Then, login to the server and check for and delete any remaining packages, files or directories relating to the package, for example:

dpkg -l | grep uwsgi
ls /etc/uwsgi
find /usr -name '*uwsgi*'

Delete a firewall setting

  1. Import the unset_firewall macro:

    {% from 'lib.sls' import unset_firewall %}
    
  2. Add a temporary macro call, for example:

    {{ unset_firewall('PUBLIC_POSTGRESQL') }}
    
  3. Deploy the relevant server, for example:

    ./run.py 'mytarget' state.apply
    
  4. Remove the temporary macro call

Delete an Apache module

  1. Add a temporary state, for example:

    headers:
      apache_module.disabled
    
  2. Run the temporary state, for example:

    ./run.py 'mytarget' state.sls_id headers core
    
  3. Remove the temporary state

Delete an htpasswd entry

  1. Add a temporary state, for example:

    delete-NAME:
      webutil.user_absent:
        - htpasswd_file: /etc/apache2/.htpasswd-NAME
    
  2. Run the temporary state, for example:

    ./run.py 'mytarget' state.sls_id delete-NAME core
    
  3. Remove the temporary state

Delete an Apache virtual host

Run, for example:

./run.py 'cove' file.remove /etc/apache2/sites-enabled/cove.conf
./run.py 'cove' file.remove /etc/apache2/sites-available/cove.conf
./run.py 'cove' file.remove /etc/apache2/sites-available/cove.conf.include

A temporary apache_site.disabled state can be used instead of removing the file in the sites-enabled directory.

Delete an Nginx virtual host

Run, for example:

./run.py 'mytarget' file.remove /etc/nginx/sites-enabled/mysite.conf
./run.py 'mytarget' file.remove /etc/nginx/sites-available/mysite.conf
./run.py 'mytarget' file.remove /etc/nginx/sites-available/mysite.conf.include

Delete a PostgreSQL user

See Delete a user.