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

Augeas changes state with setm not working #50224

Closed
mruepp opened this issue Oct 25, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@mruepp
Copy link

commented Oct 25, 2018

Description of Issue/Question

We have the following state:

Ensure logrotate permissions are configured:
  augeas.change:
    - changes:
      - setm '/files/etc/logrotate.conf//create/*[label() = "mode"]' . 0640

It does not work with:
setm /files/etc/logrotate.conf//create/*[label() = "mode"] . 0640
Error: Invalid formatted command, see debug log for details: /files/etc/logrotate.conf//create/*[label() = "mode"] . 0640

Also not with:
setm '/files/etc/logrotate.conf//create/*[label() = "mode"]' . 0640

Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1905, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1830, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/augeas.py", line 299, 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 198, in setm
                  raise TypeError("base MUST be a string!")
              TypeError: base MUST be a string!

Both commands work with augtool but not this one:
setm '/files/etc/logrotate.conf//create/*[label() = "mode"] . 0640'
Comment: Error: Invalid formatted command, see debug log for details: '/files/etc/logrotate.conf//create/*[label() = "mode"] . 0640'

Also we tried this commands, both failed with TypeError("base MUST be a string!")

Ensure logrotate permissions are configured:
  augeas.change:
    - changes:
      - setm /files/etc/*[label() =~ regexp("logrotate.*")]//create/mode . 0640

And this one:

Ensure logrotate permissions are configured:
  augeas.change:
    - context: /files/etc
    - changes:
      - setm '*[label() =~ regexp("logrotate.*")]//create/mode' . 0640

And this variations

setm '*[label() =~ regexp("logrotate.*")]//create/mode' . 0640
setm '*[label() =~ regexp("logrotate.*")]//create/mode' '.' '0640'
setm '*[label() =~ regexp("logrotate.*")]//create/mode . 0640'

setm '*[label() =~ regexp("logrotate.*")]//create/mode][ . = 0640]'

Also tried this one with various quotations:
setm /files/etc/logrotate.d//*[label() = "create"] mode 0640

Setup

(Please provide relevant configs and/or SLS files (Be sure to remove sensitive info).)

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Versions Report

Salt Version:
Salt: 2018.3.2

Dependency Versions:
cffi: 1.6.0
cherrypy: Not Installed
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.7.2
libgit2: 0.26.3
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.5.6
mysql-python: Not Installed
pycparser: 2.14
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: 0.26.4
Python: 2.7.5 (default, Jul 13 2018, 13:06:57)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 15.3.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: centos 7.5.1804 Core
locale: UTF-8
machine: x86_64
release: 3.10.0-862.14.4.el7.x86_64
system: Linux
version: CentOS Linux 7.5.1804 Core

@mruepp mruepp changed the title Augeas state setm not working as expected Augeas changes state with setm not working Oct 26, 2018

@Ch3LL

This comment has been minimized.

Copy link
Contributor

commented Oct 26, 2018

okay i'm able to replicate this. It looks like in the augeas module it compares the base path to make sure its a string but we are passing in unicode type so right here:

> 180         if type(base) != str: 
  181             raise TypeError("base MUST be a string!")      

is where its failing. ping @terminalmage can you take a look here

@Ch3LL Ch3LL added this to the Approved milestone Oct 26, 2018

@mruepp

This comment has been minimized.

Copy link
Author

commented Oct 29, 2018

This should be the desired working expression:

Ensure logrotate permissions are configured:
  augeas.change:
    - context: /files/etc
    - changes:
      - setm '*[label() =~ glob("logrotate*")]//create/mode' . 0640
@terminalmage

This comment has been minimized.

Copy link
Contributor

commented Nov 15, 2018

It looks like augeas doesn't support unicode. #50526 should fix this.

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Nov 15, 2018

Closed via #50526

@rallytime rallytime closed this Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.