Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Check file.managed replacement need #136

Open
mjtrangoni opened this issue Nov 26, 2019 · 1 comment
Open

Feature Request: Check file.managed replacement need #136

mjtrangoni opened this issue Nov 26, 2019 · 1 comment
Labels

Comments

@mjtrangoni
Copy link
Contributor

Hi,

I have one case for file.managed, where salt self changes the default value of replace from True to False, printing this warning

[WARNING ] State for file: /boot/efi/EFI/centos/grub.cfg - Neither 'source' nor 'contents' nor 'contents_pillar' nor 'contents_grains' was defined, yet 'replace' was set to 'True'. As there is no source to replace the file with, 'replace' has been set to 'False' to avoid reading the file unnecessarily.

We are changing here only the file mode and ownership so there is no need of replacing the file.

problematic state:

# EFI mode 0700
{% for grub_cfg in ['/boot/efi/EFI/centos/grub.cfg', '/boot/efi/EFI/redhat/grub.cfg'] %}
cis_grub.cfg_{{ grub_cfg }}:
  file.managed:
    - name: {{ grub_cfg }}
    - user: root
    - group: root
    - mode: '0700'
    - onlyif: test -f {{ grub_cfg }}
{% endfor %}

fixed state:

# EFI mode 0700
{% for grub_cfg in ['/boot/efi/EFI/centos/grub.cfg', '/boot/efi/EFI/redhat/grub.cfg'] %}
cis_grub.cfg_{{ grub_cfg }}:
  file.managed:
    - name: {{ grub_cfg }}
    - user: root
    - group: root
    - mode: '0700'
    - replace: False
    - onlyif: test -f {{ grub_cfg }}
{% endfor %}
@roaldnefs roaldnefs added Priority: Low Type: Enhancement New feature or request labels Nov 29, 2019
@roaldnefs
Copy link
Member

Thanks @mjtrangoni for your feature request!

In order to implement this rule we could render the states as YAML and just check if 'source' nor 'contents' nor 'contents_pillar' nor 'contents_grains' was defined.

@roaldnefs roaldnefs changed the title Check file.managed replacement need Feature Request: Check file.managed replacement need Jan 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants