augeas, syslog and defining numbered items.

95 views
Skip to first unread message

trey85stang

unread,
Mar 13, 2014, 2:24:12 PM3/13/14
to puppet...@googlegroups.com
How can one change an existing entry with augeas on a numbered entry list?

specifically I want to add entries in syslog to the entry that has "file = /var/log/messages"

I can use this search string to find the entry:


augtool> print /files/etc/syslog.conf/*/action/file[. = "/var/log/messages"]
/files/etc/syslog.conf/entry[1]/action/file = "/var/log/messages"

The augeas examples really only show editing values that would be below file.  I need to edit a a lower level then file. i.e. /files/etc/syslog.conf/entry[1]/selector[last() + 1]?

How can this be done from augeas and puppet?  (also should this go the the augeas list instead?)
Message has been deleted

trey85stang

unread,
Mar 17, 2014, 5:56:44 PM3/17/14
to puppet...@googlegroups.com
Ok,  

I figured this out.  I probably worded my issue badly but what i was looking for is the following:

#this sets a variable at the entry[#] level
defvar syslog /files/etc/syslog.conf/*[ ./action/file = "/var/log/messages"]

#these two add in the new selector entries.
set $syslog/selector[last() + 1]/facility local6
set $syslog/selector[last() + 1]/facility local7

#Now we put the selector[#] into a new variable
defvar syslog_selector1 $syslog/*[./facility = "local6"]
defvar syslog_selector2 $syslog/*[./facility = "local7"]

#configure the level for the two new entries
set $syslog_selector1/level none
set $syslog_selector2/level none

#stupid bug in syslog.aug
rm $syslog/action
set $syslog/action/file /var/log/messages

#save the changes
save

The bug,  for some reason action and file has to be listed after all the selector entries.  I have not checked for an updated syslog.aug this is on centos 5.10.

I was able to write an augeas type for this

  augeas { "syslog_local6none":

    incl => "/etc/syslog.conf",

    lens => "Syslog.lns",

    changes => [

      "defvar syslog *[ ./action/file = \"/var/log/messages\" ]",

      "set \$syslog/selector[last() + 1]/facility local6",

      "defvar syslog_selector \$syslog/*[ ./facility = \"local6\" ]",

      "set \$syslog_selector/level none",

#      "rm \$syslog/action",

#      "set \$syslog/action/file /var/log/messages",

    ],

  }



Hopefully this helps someone else as I spent way too much time figuring this out...

trey85stang

unread,
Mar 18, 2014, 10:25:31 AM3/18/14
to puppet...@googlegroups.com
One more thing I found,  I needed an onlyif for the above puppet line.

Here is a little further syntax

  augeas { "syslog_local6none":

    incl => "/etc/syslog.conf",

    lens => "Syslog.lns",

    changes => [

      "defvar syslog *[ ./action/file = \"/var/log/messages\" ]",

      "set \$syslog/selector[last() + 1]/facility local6",

      "defvar syslog_selector \$syslog/*[ ./facility = \"local6\" ]",

      "set \$syslog_selector/level none",

#      "rm \$syslog/action",

#      "set \$syslog/action/file /var/log/messages",

    ],

    onlyif => 'match *[ ./action/file = "/var/log/messages" ]/selector[facility = "local6" and level = "none" ] size == 0'

  }



So as you can see,  in the onlyif line,   you can use expressions in the []'s and continue on to a lower level.  On top of that you can use and and or's in those.  I dont know why that type of expression is not documented well.  If I didnt need to wipe out the action,  it would make the manifest much shorter and ditch the need for the variables.

Reply all
Reply to author
Forward
0 new messages