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.19k stars 5.48k forks source link

[BUG] file.managed returns None instead of inline comment #64698

Closed network-shark closed 1 year ago

network-shark commented 1 year ago

Hello salties ,

today I updated to 3006.1 and I found a big regression with the file.managed state .

Description file.managed now interprets my inline comments and replaces them with None

sharky@salt ~ % salt -V
Salt Version:
          Salt: 3006.1

Python Version:
        Python: 3.10.11 (main, May  5 2023, 02:36:14) [GCC 11.2.0]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: unknown
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: 1.6.4
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: 1.12.2
  python-gnupg: 0.4.8
        PyYAML: 5.4.1
         PyZMQ: 23.2.0
        relenv: 0.12.3
         smmap: Not Installed
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: debian 11 bullseye
        locale: utf-8
       machine: aarch64
       release: 5.10.103-v8+
        system: Linux
       version: Debian GNU/Linux 11 bullseye

Please be as specific as possible and give set-up details.

Steps to Reproduce the behavior (Include debug logs if possible and relevant)

Expected behavior file.manged should not touch my comments It worked on 3005 and before

file.manged ( truncated )

create_zsh_rc:
  file.managed:
    - name: /home/sharky/.dotfiles/.zshrc
    - user: sharky
    - group: sharky
    - mode: 0644
    - contents:
      - # Enable Backwards Search
      - #bindkey -v
      - bindkey '^R' history-incremental-search-backward
      - # Enable bash key bindings
      - # CTRL + K , CTRL + A Enable bash key bindings
      - #bindkey -e
      - # History

Line 1 and 2 got will be replaced by None instead of my comment

ID: create_zsh_rc
    Function: file.managed
        Name: /home/sharky/.dotfiles/.zshrc
      Result: True
     Comment: File /home/sharky/.dotfiles/.zshrc updated
     Started: 20:14:02.482527
    Duration: 77.046 ms
     Changes:
              ----------
              diff:
                  ---
                  +++
                  @@ -1,10 +1,10 @@
                  -# Enable Backwards Search
                  -#bindkey -v
                  +None
                  +None
                   bindkey '^R' history-incremental-search-backward
                  -# Enable bash key bindings
                  -# CTRL + K , CTRL + A Enable bash key bindings
                  -#bindkey -e
                  -# History
                  +None
                  +None
                  +None
                  +None

actual file

sharky@salt ~ % cat zshrc_
None
None
bindkey '^R' history-incremental-search-backward
None
None
None
None

At least I could found a workaround. If I use the | instead of a list then it still works.

create_zsh_rc:
  file.managed:
    - name: /home/sharky/.dotfiles/.zshrc
    - user: sharky
    - group: sharky
    - mode: 0644
    - contents: |
       # Enable Backwards Search
       #bindkey -v
       bindkey '^R' history-incremental-search-backward
       # Enable bash key bindings
       # CTRL + K , CTRL + A Enable bash key bindings
       #bindkey -e
       # History

Does work .

best regards , sebastian

OrangeDog commented 1 year ago

That is the correct behaviour. If you want to include YAML syntax inside a string then you need to quote it, e.g.

- contents:
  - "# Enable Backwards Search"
  - "#bindkey -v"
  - bindkey '^R' history-incremental-search-backward
  - "# Enable bash key bindings"
  - "# CTRL + K , CTRL + A Enable bash key bindings"
  - "#bindkey -e"
  - "# History"

It's not a regression, it's a bug fix.