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

Strange behavior between file.comment and file.uncomment #56107

Open
ArthurREGNARD opened this issue Feb 10, 2020 · 13 comments
Open

Strange behavior between file.comment and file.uncomment #56107

ArthurREGNARD opened this issue Feb 10, 2020 · 13 comments
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Execution-Module severity-low 4th level, cosemtic problems, work around exists
Milestone

Comments

@ArthurREGNARD
Copy link

Description of Issue

I can't comment and uncomment the same line in a file with the same regex.

Setup

An example.sls:

edit_file:
  file.managed:
    - name: /tmp/test
    - contents: |
        /dev/mapper/centos-swap swap                    swap    defaults        0 0

# Here the content of the file is in not commented line state : OK

comment_file:
  file.comment:
    - name: /tmp/test
    - regex: "^.*swap.*$"

# Here the content of the file is in commented line state : OK

uncomment_file:
  file.uncomment:
    - name: /tmp/test
    - regex: "^.*swap.*$"

# Here the state return  comment : Pattern already uncommented
# But the line still commented. 

Steps to Reproduce Issue

Up.

Versions Report

[root@master ~]# salt --versions-report
Salt Version:
           Salt: 2019.2.3

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.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.35.2
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: Not Installed
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 3.6.8 (default, Aug  7 2019, 17:28:10)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4.2
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.1.3.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core
@ArthurREGNARD
Copy link
Author

Related with #24907 ?

@ArthurREGNARD
Copy link
Author

Related with #55085 ?

@DmitryKuzmenko
Copy link
Contributor

@ArthurREGNARD the problem is in your regex: it's too greedy. It matches both commented and not commented lines in your file. So state thinks your line is already uncommented because it matched with your regex.
Try to use something like ^[^#].*swap.*$.
You could omit ^ and $ symbols, btw: [^#].*swap.*.

@DmitryKuzmenko
Copy link
Contributor

Feel free to re-open this if you'll have more questions, though.

@ArthurREGNARD
Copy link
Author

I'm not agree, the documentation say :

A regular expression used to find the lines that are to be uncommented.
This regex should not include the comment character. <<<<<<<<<<<<<<<<<< HERE !!
A leading ^ character will be stripped for convenience (for easily switching between comment() and uncomment()). <<<<<<<<<<<<<<<< HERE !!
The regex will be searched for from the beginning of the line, ignoring leading spaces (we prepend '^[ t]*')

https://docs.saltstack.com/en/latest/ref/states/all/salt.states.file.html#salt.states.file.uncomment

@ArthurREGNARD
Copy link
Author

@DmitryKuzmenko I can't re-open.

@OrangeDog
Copy link
Contributor

Possibly same issue as #54260

@sagetherage
Copy link
Contributor

@ArthurREGNARD does this look similar to #54260?

@DmitryKuzmenko
Copy link
Contributor

@ArthurREGNARD sorry for that I didn't know =) I've reopened this

@DmitryKuzmenko
Copy link
Contributor

@OrangeDog @sagetherage it's not. I've just checked the issue #54260 is fixed.

@DmitryKuzmenko
Copy link
Contributor

What about this one now I see this is confusing for users so we should consider possibility of fixing this if it's possible.

@DmitryKuzmenko DmitryKuzmenko added Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Execution-Module severity-low 4th level, cosemtic problems, work around exists P4 Priority 4 labels Feb 13, 2020
@DmitryKuzmenko DmitryKuzmenko added this to the Approved milestone Feb 13, 2020
@OrangeDog
Copy link
Contributor

I've just checked the issue #54260 is fixed.

Confirmed it's not fixed.

@DmitryKuzmenko
Copy link
Contributor

@OrangeDog anyway this one is another issue, not the same as #54260.

@sagetherage sagetherage removed the P4 Priority 4 label Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Core relates to code central or existential to Salt Execution-Module severity-low 4th level, cosemtic problems, work around exists
Projects
None yet
Development

No branches or pull requests

4 participants