saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.18k stars 5.48k forks source link

file.append not working #37197

Closed ghost closed 6 years ago

ghost commented 8 years ago

Description of Issue/Question

I created this state:

/etc/postfix/main.cf:
    file.append:
        - name: /etc/postfix/main.cf
        - text: |
            relayhost = smtp.wsu.edu

When I apply the state I can lots of things are being changed in it which should not be:

          ID: /etc/postfix/main.cf
    Function: file.append
      Result: True
     Comment: File /etc/postfix/main.cf is in correct state
     Started: 12:34:24.436751
    Duration: 29.894 ms
     Changes:   
              ----------
              diff:
                  --- 

                  +++ 

                  @@ -66,7 +66,7 @@

                   #default_privs = nobody

                   # INTERNET HOST AND DOMAIN NAMES
                  -#
                  +# 
                   # The myhostname parameter specifies the internet hostname of this
                   # mail system. The default is to use the fully-qualified domain name
                   # from gethostname(). $myhostname is used as a default value for many
                  @@ -83,7 +83,7 @@

                   #mydomain = domain.tld

                   # SENDING MAIL
                  -#
                  +# 
                   # The myorigin parameter specifies the domain that locally-posted
                   # mail appears to come from. The default is to append $myhostname,
                   # which is fine for small sites.  If you run a domain with multiple
                  @@ -184,7 +184,7 @@

                   #
                   # - You define $mydestination domain recipients in files other than
                   #   /etc/passwd, /etc/aliases, or the $virtual_alias_maps files.
                  -#   For example, you define $mydestination domain recipients in
                  +#   For example, you define $mydestination domain recipients in    
                   #   the $virtual_mailbox_maps files.
                   #
                   # - You redefine the local delivery agent in master.cf.
                  @@ -204,7 +204,7 @@

                   # The right-hand side of the lookup tables is conveniently ignored.
                   # In the left-hand side, specify a bare username, an @domain.tld
                   # wild-card, or specify a user@domain.tld address.
                  -#
                  +# 
                   #local_recipient_maps = unix:passwd.byname $alias_maps
                   #local_recipient_maps = proxy:unix:passwd.byname $alias_maps
                   #local_recipient_maps =
                  @@ -236,16 +236,16 @@

                   # clients in the same IP subnetworks as the local machine.
                   # On Linux, this does works correctly only with interfaces specified
                   # with the "ifconfig" command.
                  -#
                  +# 
                   # Specify "mynetworks_style = class" when Postfix should "trust" SMTP

Why? This causes the state to make changes every time it is applied although the text it should simply be appending is already appended. The end result is correct, the file does have the text appended to it.

Versions Report

Salt Version:
           Salt: 2016.3.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 1.5
          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
         pygit2: Not Installed
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.7.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.4.5.el7.x86_64
         system: Linux
        version: CentOS Linux 7.2.1511 Core
Ch3LL commented 8 years ago

@jwhite530 I'm having a hard time replicating this as shown below:

 ch3ll@thecakeisalie  ~/docker/37187  docker run -it -v /home/ch3ll/git/salt/:/testing/ ch3ll/issues:37197 /bin/bash
[root@6701e73865eb /]# salt-call --local state.sls test
[WARNING ] /testing/salt/grains/core.py:1493: DeprecationWarning: The "osmajorrelease" will be a type of an integer.

local:
----------
          ID: /etc/postfix/main.cf
    Function: file.append
      Result: True
     Comment: Appended 1 lines
     Started: 20:07:43.782199
    Duration: 7.364 ms
     Changes:   
              ----------
              diff:
                  --- 

                  +++ 

                  @@ -677,3 +677,4 @@

                   # readme_directory: The location of the Postfix README files.
                   #
                   readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
                  +relayhost = smtp.wsu.edu

Summary for local
------------
Succeeded: 1 (changed=1)
Failed:    0
------------
Total states run:     1
Total run time:   7.364 ms
[root@6701e73865eb /]# salt-call --local state.sls test
[WARNING ] /testing/salt/grains/core.py:1493: DeprecationWarning: The "osmajorrelease" will be a type of an integer.

local:
----------
          ID: /etc/postfix/main.cf
    Function: file.append
      Result: True
     Comment: File /etc/postfix/main.cf is in correct state
     Started: 20:07:51.831142
    Duration: 5.396 ms
     Changes:   

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

Also here is a docker container fo my test case:

  1. docker run -it -v /home/ch3ll/git/salt/:/testing/ ch3ll/issues:37197 salt-call --local state.sls test (where /home/ch3ll/git/salt/ is a local git clone repo of salt)

Can you share a sanitized version of the postfix file that is causing issues. I simply did a yum install postfix and used the default postfix file.Or provide any other information to help me replicate this issue or point out where my test case is incorrect. Thanks

stale[bot] commented 6 years ago

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.