Skip to content

salt.states.augeas.change example from docs fails with exception #16383

Closed

Description

@interjection

Running CentOS 7 Vagrant box w/ salt provisioner configured and masterless salt v2014.7.0rc3, also tried the latest develop branch.

An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1529, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/states/augeas.py", line 182, in change
                  result = __salt__['augeas.execute'](context=context, lens=lens, commands=changes)
                File "/usr/lib/python2.7/site-packages/salt/modules/augeas_cfg.py", line 159, in execute
                  func(**args)
                File "/usr/lib/python2.7/site-packages/augeas.py", line 266, in insert
                  raise ValueError("Unable to insert label!")
              ValueError: Unable to insert label!

To reproduce:

zabbix-service:
  augeas.change:
    - lens: services
    - context: /files/etc/services
    - changes:
      - ins service-name after service-name[last()]
      - set service-name[last()] zabbix-agent
      - set service-name[. = 'zabbix-agent']/#comment "Zabbix Agent service"
      - set service-name[. = 'zabbix-agent']/port 10050
      - set service-name[. = 'zabbix-agent']/protocol tcp

Activity

  1. cachedout commented on Oct 6, 2014

    @cachedout
    Contributor

    Thanks for the report. We'll investigate this.

  2. added
    bug
    severity-low
    on Oct 6, 2014
  3. added this to the Approved milestone on Oct 6, 2014
  4. interjection commented on Oct 6, 2014

    @interjection
    Author

    Just adding some quick examples to test against:

    test-service:
        augeas.change:
            - lens: services
            - context: /files/etc/services
            - changes:
                - ins service-name after service-name[last()]
                - set service-name[last()] test-service
                - set service-name[. = 'test-service']/port 10075
                - set service-name[. = 'test-service']/protocol tcp
                - ins service-name after service-name[last()]
                - set service-name[last()] test-service
                - set service-name[. = 'test-service'][2]/port 10075
                - set service-name[. = 'test-service'][2]/protocol udp
            - unless: grep "test-service" /etc/services
    

    This runs fine in augtool:

    ins service-name after /files/etc/services/service-name[last()]
    set /files/etc/services/service-name[last()] test-service
    set /files/etc/services/service-name[. = 'test-service']/port 10075
    set /files/etc/services/service-name[. = 'test-service']/protocol tcp
    ins service-name after /files/etc/services/service-name[last()]
    set /files/etc/services/service-name[last()] test-service
    set /files/etc/services/service-name[. = 'test-service'][2]/port 10075
    set /files/etc/services/service-name[. = 'test-service'][2]/protocol udp
    

    Another example:

    pam-su:
        augeas.change:
            - lens: pam
            - context: /files/etc/pam.d/su
            - changes:
                - ins 01 after *[module = 'pam_rootok.so'][control = 'sufficient'][type ='auth'][last()]
                - set 01/type auth
                - set 01/control requisite
                - set 01/module pam_wheel.so
                - set 01/argument group=wheel
            - unless: grep "group=wheel" /etc/pam.d/su
    
    

    This runs fine in augtool:

    ins 01 after /files/etc/pam.d/su/*[module = 'pam_rootok.so'][control = 'sufficient'][type ='auth'][last()]
    set /files/etc/pam.d/su/01/type auth
    set /files/etc/pam.d/su/01/control requisite
    set /files/etc/pam.d/su/01/module pam_wheel.so
    set /files/etc/pam.d/su/01/argument group=wheel
    
  5. mens commented on Dec 16, 2014

    @mens
    Contributor

    The problem seems to be the #comment part. I haven't found a working way to do something like:

    set /files/etc/hosts/#comment[2] "this is the second comment"{code}

    This always results in the error above.

  6. added a commit that references this issue on May 20, 2015
    3686dcd
  7. kartiksubbarao commented on May 20, 2015

    @kartiksubbarao
    Contributor

    I ran into this problem as well. It looks like the arguments to the augeas insert function weren't being parsed in the correct order. Above is a patch that resolves the issue.

  8. added
    severity-medium
    P2
    Platform
    fixed-pls-verify
    and removed
    severity-low
    on May 21, 2015
  9. rsuarezsoto commented on Jul 26, 2016

    @rsuarezsoto

    Sorry to comment on a closed issue, but I'm struggling with something that looks very much like this. I get this exception when I try to use augeas to modify /etc/pam.d/system-auth:

              ID: system-auth_augeas
        Function: augeas.change
          Result: False
         Comment: An exception occurred in this state: Traceback (most recent call last):
                    File "/usr/lib/python2.7/site-packages/salt/state.py", line 1723, in call
                      **cdata['kwargs'])
                    File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1650, in wrapper
                      return f(*args, **kwargs)
                    File "/usr/lib/python2.7/site-packages/salt/states/augeas.py", line 283, in change
                      commands=changes, load_path=load_path)
                    File "/usr/lib/python2.7/site-packages/salt/modules/augeas_cfg.py", line 245, in execute
                      func(**args)
                    File "/usr/lib/python2.7/site-packages/augeas.py", line 369, in insert
                      raise ValueError("Unable to insert label!")
                  ValueError: Unable to insert label!
         Started: 12:11:16.559663
        Duration: 8.564 ms
         Changes:
    

    This is the SLS code:

    python-augeas:
      pkg.installed
    
    system-auth_augeas:
      augeas.change:
        - require:
          - pkg: python-augeas
        - lens: pam
        - context: /files/etc/pam.d/system-auth/
        - changes:
          - ins 02 after *[type='auth'][control='sufficient'][module='pam_unix.so']
          - set 02/type auth
          - set 02/control sufficient
          - set 02/module pam_faillock.so
          - set 02/argument authsucc

    This works if I run it through augtool. This is my input:

    ins 02 after /files/etc/pam.d/system-auth/*[type='auth'][control='sufficient'][module='pam_unix.so']
    set /files/etc/pam.d/system-auth/02/type auth
    set /files/etc/pam.d/system-auth/02/control sufficient
    set /files/etc/pam.d/system-auth/02/module pam_faillock.so
    set /files/etc/pam.d/system-auth/02/argument authsucc
    save
    

    I'm using CentOS 7 and Saltstack 2016.3.1. Am I doing something wrong?

    Thanks in advance.

  10. kartiksubbarao commented on Aug 1, 2016

    @kartiksubbarao
    Contributor

    I took out - lens: pam in your code and it worked -- does that work for you as well? If so, the problem might be related to issue #24274 which is still open, although that has a different error message.

  11. rsuarezsoto commented on Aug 2, 2016

    @rsuarezsoto

    No, sorry, removing "lens: pam" changes nothing. But something weird is happening, because if I change "lens: pam" to a lens that doesn't exist ("lens: whatever"), the same error appears. It's as if the lens wasn't being used at all.

  12. kartiksubbarao commented on Aug 2, 2016

    @kartiksubbarao
    Contributor

    Strange that removing the lens worked for me but not for you. Not sure what to make of it at this point. I'd suggest opening up a separate issue for the problem that you're seeing so that it can get better attention from the developers. It may still be related to #24274, or it may be a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Platformbugfixed-pls-verifyseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions