Remove files and reload systemd

160 views
Skip to first unread message

brad.v...@gmail.com

unread,
Oct 29, 2021, 9:31:00 AM10/29/21
to Salt-users
Trying to remove some system level CPU and memory quotas from McAfee services.  I think they are causing more problems than without them.  We are currently running 3003.2.

mcafee.ma.service.d_remove:
  file.remove:
    - name: /etc/systemd/system/mcafee.ma.service.d/
  module.run:
    - name: service.systemctl_reload
    - onchanges:
      - file: /etc/systemd/system/mcafee.ma.service.d/50-CPUQuota.conf

mfeespd.service.d_remove:
  file.remove:
    - name: /etc/systemd/system/mfeespd.service.d/
  module.run:
    - name: service.systemctl_reload
    - onchanges:
      - file: /etc/systemd/system/mfeespd.service.d/50-CPUQuota.conf

mfetpd.service.d_remove:
  file.remove:
    - name: /etc/systemd/system/mfetpd.service.d/
  module.run:
    - name: service.systemctl_reload
    - onchanges:
      - file: /etc/systemd/system/mfetpd.service.d/50-CPUQuota.conf

Gives me file.remove was not found in SLS quota-rm
Reason: file.remove is not available.

According to https://docs.saltproject.io/en/3003/ref/modules/all/salt.modules.file.html it says it was changed in version 3000.   Anyone know what I am doing wrong?

Dennis Payne

unread,
Oct 29, 2021, 9:41:35 AM10/29/21
to salt-...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/95be1627-42b5-4905-be1c-de2cddfce4c9n%40googlegroups.com.

brad.v...@gmail.com

unread,
Oct 29, 2021, 10:22:06 AM10/29/21
to Salt-users
Thanks!  file.absent did work to remove the directory.  However, the module run failed.  It said the requisites were not found - I guess that is because they were just deleted.  I just want to do a daemon reload once if any or all of those directories are deleted.  I guess I could set up a jinja variable if the directory exists and then reload if that variable is set?

Phipps, Thomas

unread,
Oct 29, 2021, 11:13:05 AM10/29/21
to salt-...@googlegroups.com

file.absent should remove the directory. if it doesn’t please report the error. file.remove is not a state. as for the requisites. they failed because they don’t exist but not because “they were removed” requisites monitor states not the filesystem. so a onchanges: file: /etc/systemd/system/mfeespd.service.d/50-CPUQuota.conf requisite is looking for a state with a file module with a state id or - name of /etc/systemd/system/mfeespd.service.d/50-CPUQuota.conf you do not have one in this list. The closest thing you have is a file.remove with a name of /etc/systemd/system/mcafee.ma.service.d/ which does not match. your onchanges could be file mfetpd.service.d_removeto better show what requisites are monitoring.


brad.v...@gmail.com

unread,
Nov 1, 2021, 4:35:01 AM11/1/21
to Salt-users
I would say I most likely do not understand watches correctly.  :)
I will have to read up on that more.  Instead, I modified such as:

{% set reload = 0 %}
{% if salt['file.directory_exists']('/etc/systemd/system/mcafee.ma.service.d') %}
{% set reload = 1 %}
{% endif %}
{% if salt['file.directory_exists']('/etc/systemd/system/mfeespd.service.d') %}
{% set reload = 1 %}
{% endif %}
{% if salt['file.directory_exists']('/etc/systemd/system/mfetpd.service.d') %}
{% set reload = 1 %}
{% endif %}

mcafee.ma.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mcafee.ma.service.d/

mfeespd.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mfeespd.service.d/

mfetpd.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mfetpd.service.d/

{% if reload %}
quota_rm_reload_systemd:
  cmd.run:
    - name: systemctl daemon-reload
{% endif %}

Thanks!

Phipps, Thomas

unread,
Nov 1, 2021, 11:27:35 AM11/1/21
to salt-...@googlegroups.com

That works, as long as you are just removing the directories.

this should also do the trick without the jinja

mcafee.ma.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mcafee.ma.service.d/

mfeespd.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mfeespd.service.d/

mfetpd.service.d_remove:
  file.absent:
    - name: /etc/systemd/system/mfetpd.service.d/

quota_rm_reload_systemd:
  cmd.run:
    - name: systemctl daemon-reload
    - onchanges_any:
      - file: mcafee.ma.service.d_remove
      - file: mfetpd.service.d_remove
      - file: mfetpd.service.d_remove

brad.v...@gmail.com

unread,
Nov 2, 2021, 4:36:20 AM11/2/21
to Salt-users
Thanks!  Much cleaner.  :)
Reply all
Reply to author
Forward
0 new messages