saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.14k stars 5.47k forks source link

[BUG] Augeas provides actions but not checks #65352

Closed hramrach closed 1 year ago

hramrach commented 1 year ago

Description

Not sure this is a bug in the docs of if this is deficiency of the augeas plugin.

The docs say https://docs.saltproject.io/en/latest/ref/states/all/salt.states.augeas.html

zabbix-service:
  augeas.change:
    - lens: services.lns
    - context: /files/etc/services
    - changes:
      - ins service-name after service-name[last()]
      - set service-name[last()] "zabbix-agent"
      - set "service-name[. = 'zabbix-agent']/port" 10050
      - set "service-name[. = 'zabbix-agent']/protocol" tcp
      - set "service-name[. = 'zabbix-agent']/#comment" "Zabbix Agent service"
      - rm "service-name[. = 'im-obsolete']"
    - unless: grep "zabbix-agent" /etc/services

This is not a way to manage the file. The string zabbix-agent may be in the file but commented out. There might be a service like zabbix-agent-ng. When the file is modified by augeas the check that the modification was applied should also be done by augeas.

welcome[bot] commented 1 year ago

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at saltproject@vmware.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

OrangeDog commented 1 year ago

As far as I know, augeas doesn't work like that. If you tell it to ins then it does.

If the example were changed to grep '^zabbix-agent\s' /etc/services would that make you happier?

hramrach commented 1 year ago

No, I mean that Augeas upstream provides both functions to change the file and get data from the file.

Then if I did not use Salt but rather Augeas upstream tools I could write a check that parses the file and looks if "zabbix-agent" service definition is present, and execute the actions to add it when it is not.

However, here the check is executed with 'grep' which has very little idea about the structure of the file rather than with Augeas, the very thing Augeas is supposed to prevent.

OrangeDog commented 1 year ago

Then this should be a feature request that's going to require some design of how to implement that in a Salt state.

hramrach commented 1 year ago

So it's not merely an omission in the documentation.

Does not look like I can change the labels to mark this a feature.

OrangeDog commented 1 year ago

Create a new issue using the feature template and fill in the details.

hramrach commented 1 year ago

Moved to #65359

OrangeDog commented 1 year ago

Ignoring half the template was not helpful.