salt icon indicating copy to clipboard operation
salt copied to clipboard

state file.line warning

Open damon-atkins opened this issue 9 years ago • 12 comments

Description of Issue/Question

Setup

Steps to Reproduce Issue

Using file.line results in the following warning [WARNING ] file.managed State for file: filename - 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.

Here is the bit of the code which is the cause within file.line state

    if not name:
        return _error(ret, 'Must provide name to file.line')

    managed(name, create=create, user=user, group=group, mode=file_mode)

    check_res, check_msg = _check_file(name)
...

managed is called with name=filename create=False user=None group=None mode=None which gives the following error (note replace defaults to True for managed): [WARNING ] file.managed State for file: filename - 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.

I suspect the fix is to add replace=False when calling managed(). Also note the missing windows permission support.

However it seems to be an overkill to call such a large function to set permissions.

Versions Report

salt-call --versions-report
Salt Version:
           Salt: 2016.11.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: 1.10.6
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.4.3
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov  6 2016, 00:28:07)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.3.1611 Core
        machine: x86_64
        release: 3.10.0-514.16.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.3.1611 Core

damon-atkins avatar Apr 28 '17 15:04 damon-atkins

Is the behavior of file.line with mode replace not working correctly either? Or you are just seeing the warning?

Ch3LL avatar Apr 28 '17 19:04 Ch3LL

Hi @Ch3LL, When file.line is not making the expected change request in a state, then it results in people investigation down the wrong path. i.e. it confuses any issue. I suspect the warning is printed every-time file.line is used.

I suspect the quick fix is: From managed(name, create=create, user=user, group=group, mode=file_mode) To managed(name, create=create, user=user, group=group, mode=file_mode, replace=False)

Another issue should be raise for the lack of windows support in terms of permissions across most of state.file.*

damon-atkins avatar Apr 29 '17 02:04 damon-atkins

@Ch3LL any more info needed?

damon-atkins avatar May 01 '17 07:05 damon-atkins

Seeing the same warning using file.line:

# salt-call state.apply common.epel_check-mk-agent -l info
[INFO    ] Loading fresh modules for state activity
[INFO    ] Running state [/etc/yum.repos.d/epel.repo] at time 10:55:42.180057
[INFO    ] Executing state file.line for /etc/yum.repos.d/epel.repo
[INFO    ] Executing command ['git', '--version'] in directory '/root'
[INFO    ] Executing command 'test -e /etc/yum.repos.d/epel.repo' in directory '/root'
[WARNING ] State for file: /etc/yum.repos.d/epel.repo - 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.
[INFO    ] No changes needed to be made
[INFO    ] Completed state [/etc/yum.repos.d/epel.repo] at time 10:55:42.848073 duration_in_ms=668.016
local:
----------
          ID: /etc/yum.repos.d/epel.repo
    Function: file.line
      Result: True
     Comment: No changes needed to be made
     Started: 10:55:42.180057
    Duration: 668.016 ms
     Changes:

Summary for local
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time: 668.016 ms

Contents of the sls file:

/etc/yum.repos.d/epel.repo:
  file.line:
    - backup: True
    - mode: Ensure
    - location:
      - start
    - before: '\[epel-debuginfo\]'
    - indent: True
    - content: 'exclude=check-mk-agent*'
    - onlyif: 'test -e /etc/yum.repos.d/epel.repo'

I am only seeing this in 2016.11.4. The formula does not show the warning in 2016.11.3. Salt versions from problematic server:

Salt Version:
           Salt: 2016.11.4

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: 3.4.3
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov  6 2016, 00:28:07)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.3.1611 Core
        machine: x86_64
        release: 3.10.0-514.16.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.3.1611 Core

The formula does work as expected, just throws the warning.

jmcook1 avatar May 02 '17 15:05 jmcook1

Seeming the same warning with 2016.11.4, but /etc/logrotate.d/nginx is updated correctly:

nginx_rotation_size:
    file.line:
        - name: /etc/logrotate.d/nginx
        - content: size 512k
        - match: daily
        - mode: Replace

Results in:

[WARNING ] State for file: /etc/logrotate.d/nginx - 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.

andrew-regan avatar May 09 '17 13:05 andrew-regan

Can confirm this in both 2016.11.4 and 2016.11.5.

pirxthepilot avatar Jun 27 '17 20:06 pirxthepilot

I am seeing the same thing here on 2016.11.5 and 4. I tried @damon-atkins solution and it works.

@damon-atkins would you put in a pull request for this please.

aabognah avatar Jun 28 '17 20:06 aabognah

Still seeing this in 2017.7.1. Are there any updates to this?

d-shi avatar Dec 06 '17 00:12 d-shi

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Mar 31 '19 01:03 stale[bot]

:+1:

andrew-regan avatar Mar 31 '19 12:03 andrew-regan

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Mar 31 '19 12:03 stale[bot]

Assuming the proposed fix was correct, https://github.com/saltstack/salt/commit/2fd172e07bca3e6379ddac5095130231ff7c7745 should have closed this. If this is still around, please let me know (preferably with an example) and I'll be happy to re-open!

waynew avatar Jun 27 '19 18:06 waynew