Skip to content

[BUG] augeas formatting and saving errors with httpd.lns #65254

Closed

Description

@kartiksubbarao

Description
Reopening #24274 and #34918, two augeas httpd.lns bugs that were marked as stale and closed, but are still present in salt 3006.3. The straightforward implementation fails with "Invalid formatted command". When adding extra quotes to pacify that error, the state fails with "Error: Augeas.save() failed: No error". Both the additional quoting and removing "lens: httpd.lns" are needed to work around the issues.

Setup
pypi install of salt 3006.3 and python-augeas on Ubuntu 22.04.

Steps to Reproduce the behavior
First, as a reference, here is the augtool command that works fine:

augtool set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg' /etc/ssl/certs/cert1.pem

Here is the straightforward salt state:

/etc/apache2/sites-available/default-ssl.conf:
  augeas.change:
    - lens: httpd.lns
    - context: /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost
    - changes:
      - set directive[. = "SSLCertificateFile"]/arg /etc/ssl/certs/cert1.pem

When I run this, I get the following error. Excerpt from the -l all log (the full log doesn't seem to have any other useful info):

[TRACE   ] Slot processing list value: set directive[. = "SSLCertificateFile"]/arg /etc/ssl/certs/cert1.pem
[ERROR   ] set takes (1, 2) args: ['directive[.', '=', 'SSLCertificateFile]/arg', '/etc/ssl/certs/cert1.pem']
[ERROR   ] Error: Invalid formatted command, see debug log for details: directive[. = "SSLCertificateFile"]/arg /etc/ssl/certs/cert1.pem
[...]
          ID: /etc/apache2/sites-available/default-ssl.conf
    Function: augeas.change
      Result: False
     Comment: Error: Invalid formatted command, see debug log for details: directive[. = "SSLCertificateFile"]/arg /etc/ssl/certs/cert1.pem
     Started: 12:14:15.057841
    Duration: 8.454 ms
     Changes:   

Adding quotes to the changes in the state:

/etc/apache2/sites-available/default-ssl.conf:
  augeas.change:
    - lens: httpd.lns
    - context: /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost
    - changes:
      - "set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = \"SSLCertificateFile\"]/arg' /etc/ssl/certs/cert1.pem"

When I run this, I get:

[TRACE   ] Slot processing list value: set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg' /etc/ssl/certs/cert1.pem
[DEBUG   ] set: {'path': '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg', 'value': '/etc/ssl/certs/cert1.pem'}
[ERROR   ] Error: Augeas.save() failed: No error
[INFO    ] Completed state [/etc/apache2/sites-available/default-ssl.conf] at time 12:32:26.598838 (duration_in_ms=9.537)
[...]
          ID: /etc/apache2/sites-available/default-ssl.conf
    Function: augeas.change
      Result: False
     Comment: Error: Augeas.save() failed: No error
     Started: 12:32:26.589301
    Duration: 9.537 ms
     Changes:

Finally, when I remove httpd.lns:

/etc/apache2/sites-available/default-ssl.conf:
  augeas.change:
    - context: /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost
    - changes:
      - "set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = \"SSLCertificateFile\"]/arg' /etc/ssl/certs/cert1.pem"

It works:

[TRACE   ] Slot processing list value: set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg' /etc/ssl/certs/cert1.pem
[DEBUG   ] set: {'path': '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg', 'value': '/etc/ssl/certs/cert1.pem'}
[INFO    ] {'updates': ['set \'/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg\' /etc/ssl/certs/cert1.pem']}
[...]
          ID: /etc/apache2/sites-available/default-ssl.conf
    Function: augeas.change
      Result: True
     Comment: Changes have been saved
     Started: 12:35:33.694015
    Duration: 1963.578 ms
     Changes:
              ----------
              updates:
                  - set '/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/directive[. = "SSLCertificateFile"]/arg' /etc/ssl/certs/cert1.pem

Expected behavior
Expected behavior is to run the first example state above without errors. Please fix both bugs -- the need to remove httpd.lns (previously reported as #24274), and the need to add the extra quotes (previously reported as #34918; if the quoting is now intentionally needed, please document this).

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3006.3
 
Python Version:
        Python: 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
 
Dependency Versions:
          cffi: 1.15.1
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.2
       libgit2: Not Installed
  looseversion: 1.3.0
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.6
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 23.1
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.0
        pygit2: Not Installed
  python-gnupg: Not Installed
        PyYAML: 6.0.1
         PyZMQ: 25.1.1
        relenv: Not Installed
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
System Versions:
          dist: ubuntu 22.04.3 jammy
        locale: utf-8
       machine: x86_64
       release: 5.15.0-79-generic
        system: Linux
       version: Ubuntu 22.04.3 jammy

Activity

  1. added
    bug
    on Sep 21, 2023
  2. OrangeDog commented on Sep 25, 2023

    @OrangeDog
    Contributor

    The error is not the same as in the original issue. Now it says:

    Error: Augeas.save() failed: No error

    I will also note that the 22.04 version of python-augeas is 0.5.0 (from 2014), wheras the latest on PyPi is 1.1.0 . The latter version may work correctly.

  3. kartiksubbarao commented on Sep 25, 2023

    @kartiksubbarao
    ContributorAuthor

    Hi @OrangeDog:

    1. The previous error in augeas error with apache config files - unable to save to file #24274 said "Error: unable to save to file". This seems to track fairly similarly with the current message "Error: Augeas.save() failed: No error". Both seem to be about a failure to save to the file.
    2. For these test runs I did pip install python-augeas from PyPi, version 1.1.0 as you indicated. Unfortunately this did not work. (salt 3006.3 was also installed from PyPi as mentioned above).
  4. OrangeDog commented on Sep 25, 2023

    @OrangeDog
    Contributor

    Both seem to be about a failure to save to the file.

    No, the new one seems to be a failure to interpret the API response.

  5. kartiksubbarao commented on Sep 25, 2023

    @kartiksubbarao
    ContributorAuthor

    Well -- whatever the case may end up being, hopefully someone from the salt team can take an in-depth look and fix the problem :-)

  6. kartiksubbarao commented on Sep 25, 2023

    @kartiksubbarao
    ContributorAuthor

    Tagging some folks from the salt team who responded to the original cases that were unfortunately closed without being resolved. Any chance you can help get this issue some attention? @jfindlay @sagetherage @Ch3LL

  7. self-assigned this
    on Sep 25, 2023
  8. added this to the Argon v3008 milestone on Sep 25, 2023
  9. 1 remaining item

  10. added this to the Argon v3008.3 milestone on Jul 14, 2026
  11. added
    severity-medium
    on Oct 16, 2026
  12. dwoz commented on Oct 16, 2026

    @dwoz
    Contributor

    Thanks for the original report. This issue has been open for more than three years without recent activity and carries a severity label below severity-high. As part of a backlog cleanup, we're closing older low- and medium-severity issues so triage can focus on reports against currently supported releases.

    Closing isn't a judgement that the problem wasn't real — only that the codebase has moved through several releases since this was filed, and much of the surrounding code has changed.

    If you — or anyone else — can still reproduce this on the 3008.x LTS release, please leave a comment with a reproduction and a maintainer will reopen. The original reporter can also reopen directly.

  13. kartiksubbarao commented on Oct 16, 2026

    @kartiksubbarao
    ContributorAuthor

    FYI for anyone who is interested -- I asked ChatGPT to track down the root cause of these issues, here's what it said:


    ChatGPT: I investigated the original reports (#24274 and #34918), the 2023 reproduction in this issue, and the implementation of Salt's Augeas integration. There appear to be two distinct problems, and we've now experimentally reproduced the underlying cause of the more obscure one.

    1. Invalid formatted command

    This comes from Salt's use of shlex_split() to parse Augeas commands.

    The original command:

    set directive[. = "SSLCertificateFile"]/arg /etc/ssl/certs/cert1.pem
    

    gets split into more arguments than the set operation expects because of the spaces in the Augeas path predicate.

    Quoting the entire path fixes that:

    set 'directive[. = "SSLCertificateFile"]/arg' /etc/ssl/certs/cert1.pem
    

    This is a command-parsing issue in Salt's wrapper, not a failure of Augeas itself.

    2. Augeas.save() failed: No error

    This problem is more interesting.

    In the historical Salt implementation, when both lens and context are specified, Salt disables Augeas's automatic lens loading and explicitly constructs a transform:

    flags = _Augeas.NO_MODL_AUTOLOAD if lens and context else _Augeas.NONE
    aug = _Augeas(flags=flags, loadpath=load_path)
    
    if lens and context:
        aug.add_transform(lens, re.sub("^/files", "", context))
        aug.load()

    The critical line is:

    aug.add_transform(lens, re.sub("^/files", "", context))

    Salt passes context to add_transform() as though it identifies a filesystem file.

    But the original state specifies:

    /files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost
    

    This is an Augeas tree path, extending inside the Apache configuration file.

    After removing /files, Salt supplies:

    /etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost
    

    to add_transform().

    Augeas expects a filesystem filename or pattern here, not a path to nodes within a parsed configuration. The actual file ends at default-ssl.conf.

    This explains the difference between specifying lens and omitting it. Without an explicit lens, Augeas can automatically load the actual Apache configuration file. With an explicit lens, Salt instead constructs a transform using the nested context, which does not select the intended file.

    3. Experimental confirmation

    We tested this directly using Python's Augeas bindings in an isolated Ubuntu container.

    Three combinations were tested:

    Lens Transform path File loaded?
    Httpd.lns Actual configuration filename Yes
    Httpd.lns Filename plus /IfModule/VirtualHost No
    httpd.lns Actual configuration filename Yes

    This also ruled out lens-name capitalization as the cause.

    We then recreated the problematic transform, performed the set operation, and called aug.save() against a temporary copy of the Apache configuration.

    The result was exactly the exception reported in 2023:

    Loaded: []
    Save failed: AugeasIOError('Augeas.save() failed: No error')
    

    However, inspecting Augeas's internal error tree revealed the underlying failure:

    /augeas/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/error = 'canon_augorig'
    /augeas/files/etc/apache2/sites-available/default-ssl.conf/IfModule/VirtualHost/error/message = 'Not a directory'
    

    This is the smoking gun.

    Augeas was attempting to handle a path extending beneath default-ssl.conf as a filesystem path. But default-ssl.conf is a regular file, not a directory, so the operating system returned Not a directory.

    The generic Python exception obscured this information because the useful diagnostics were recorded in Augeas's internal error tree.

    4. Conclusion

    The investigation identified two separate causes:

    1. Command parsing: Salt's shell-style argument parser splits unquoted Augeas path expressions containing spaces.
    2. Explicit lens handling: Salt uses context both to identify a location in the Augeas tree and, when an explicit lens is supplied, to select a filesystem file for add_transform(). Those are not necessarily interchangeable.

    The second problem can be avoided by specifying the actual configuration filename as context and moving the remaining Augeas tree path into the set command. That is also consistent with Salt's documented expectation that context identify a file.

    The experiments directly confirmed the incorrect file selection and reproduced the exact save exception and underlying Not a directory diagnostic. They were conducted against current Augeas bindings, not through the original Salt 3006.3 execution module, so they establish the failure mechanism rather than an end-to-end reproduction on that historical release.

    Finally, Salt 3008.x has removed the augeas.change state and its corresponding execution module from core. Consequently, the original SLS cannot be reproduced unchanged on a stock 3008.x installation.

    Although that limits testing against the current LTS release, the underlying behavior reported in 2015 and again in 2023 now has a concrete, experimentally supported explanation.

  14. dwoz commented on Oct 22, 2026

    @dwoz
    Contributor

    Reopening based on the follow-up comment above.

  15. reopened this on Oct 22, 2026
  16. kartiksubbarao commented on Oct 22, 2026

    @kartiksubbarao
    ContributorAuthor

    Thanks @dwoz for reopening the case. I did some additional investigation and testing, and I realized that I've been somewhat chasing my own tail on this issue. It turns out that I didn't fully connect the dots between #24274 and #24275, another issue I reported back in 2015.

    In that issue, I discovered that the context argument to augeas.change needs to resolve to an actual file, rather than an arbitrary path within the Augeas tree. The salt team updated the documentation accordingly. For some reason, neither I nor the salt team closed #24274 at that time. Maybe I was still focused on the fact that it worked when lens: httpd.lns was not specified, so maybe there was a pathway to get it to work even when context didn't resolve to an actual file? That would have been good to see implemented, but I could understand if the developers felt that would introduce more complexity into the code.

    In any case, I likely memory-holed the resolution to #24275 a few years later when #24274 got marked stale. I kept going back to the original notes and reproducing the same error. Which then carried forward into reviving #24274 as this issue. (#34918-type behavior seems to have been attempted to be addressed by #34640, but was then reverted by #38115, and the documentation updated by #42203).

    I also confirmed today with Salt 3006.28 that explicitly specifying lens: httpd.lns works properly when context resolves to the actual file. I'm going to close this case now, since the current behavior is documented.

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

    bugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions