hercules-team / augeas

A configuration editing tool and API
http://augeas.net/
GNU Lesser General Public License v2.1
486 stars 199 forks source link

logrotate cannot save, "Failed to match" #103

Closed jeffreymlewis closed 10 years ago

jeffreymlewis commented 10 years ago

When trying to add a "file" to /etc/logrotate.d/rsyslog I get a, "Failed to match" error when saving. This happens with augeas version 0.10.0 (shipping with Ubuntu precise) and version 1.2.0. Here's an example with augeas version 1.2.0 on Ubuntu 12.04 LTS.

jlewis@ops02:~/tmp/augeas-1.2.0/src$ ./augtool --version
augtool 1.2.0 <http://augeas.net/>
Copyright (C) 2007-2011 David Lutterkort
License LGPLv2+: GNU LGPL version 2.1 or later
                 <http://www.gnu.org/licenses/lgpl-2.1.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David Lutterkort

jlewis@ops02:~/tmp/augeas-1.2.0/src$ sudo ./augtool -I ../lenses

augtool> print /files/etc/logrotate.d/rsyslog/*[rotate = '4']
/files/etc/logrotate.d/rsyslog/rule[2]
/files/etc/logrotate.d/rsyslog/rule[2]/file[1] = "/var/log/mail.info"
/files/etc/logrotate.d/rsyslog/rule[2]/file[2] = "/var/log/mail.warn"
/files/etc/logrotate.d/rsyslog/rule[2]/file[3] = "/var/log/mail.err"
/files/etc/logrotate.d/rsyslog/rule[2]/file[4] = "/var/log/mail.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[5] = "/var/log/daemon.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[6] = "/var/log/kern.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[7] = "/var/log/auth.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[8] = "/var/log/user.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[9] = "/var/log/lpr.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[10] = "/var/log/cron.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[11] = "/var/log/debug"
/files/etc/logrotate.d/rsyslog/rule[2]/file[12] = "/var/log/messages"
/files/etc/logrotate.d/rsyslog/rule[2]/rotate = "4"
/files/etc/logrotate.d/rsyslog/rule[2]/schedule = "weekly"
/files/etc/logrotate.d/rsyslog/rule[2]/missingok = "missingok"
/files/etc/logrotate.d/rsyslog/rule[2]/ifempty = "notifempty"
/files/etc/logrotate.d/rsyslog/rule[2]/compress = "compress"
/files/etc/logrotate.d/rsyslog/rule[2]/delaycompress = "delaycompress"
/files/etc/logrotate.d/rsyslog/rule[2]/sharedscripts = "sharedscripts"
/files/etc/logrotate.d/rsyslog/rule[2]/postrotate = "\t\treload rsyslog >/dev/null 2>&1 || true"

augtool> set /files/etc/logrotate.d/rsyslog/*[rotate = '4']/file[. = '/var/log/jlewis2.log'] /var/log/jlewis2.log

augtool> print /files/etc/logrotate.d/rsyslog/*[rotate = '4']
/files/etc/logrotate.d/rsyslog/rule[2]
/files/etc/logrotate.d/rsyslog/rule[2]/file[1] = "/var/log/mail.info"
/files/etc/logrotate.d/rsyslog/rule[2]/file[2] = "/var/log/mail.warn"
/files/etc/logrotate.d/rsyslog/rule[2]/file[3] = "/var/log/mail.err"
/files/etc/logrotate.d/rsyslog/rule[2]/file[4] = "/var/log/mail.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[5] = "/var/log/daemon.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[6] = "/var/log/kern.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[7] = "/var/log/auth.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[8] = "/var/log/user.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[9] = "/var/log/lpr.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[10] = "/var/log/cron.log"
/files/etc/logrotate.d/rsyslog/rule[2]/file[11] = "/var/log/debug"
/files/etc/logrotate.d/rsyslog/rule[2]/file[12] = "/var/log/messages"
/files/etc/logrotate.d/rsyslog/rule[2]/rotate = "4"
/files/etc/logrotate.d/rsyslog/rule[2]/schedule = "weekly"
/files/etc/logrotate.d/rsyslog/rule[2]/missingok = "missingok"
/files/etc/logrotate.d/rsyslog/rule[2]/ifempty = "notifempty"
/files/etc/logrotate.d/rsyslog/rule[2]/compress = "compress"
/files/etc/logrotate.d/rsyslog/rule[2]/delaycompress = "delaycompress"
/files/etc/logrotate.d/rsyslog/rule[2]/sharedscripts = "sharedscripts"
/files/etc/logrotate.d/rsyslog/rule[2]/postrotate = "\t\treload rsyslog >/dev/null 2>&1 || true"
/files/etc/logrotate.d/rsyslog/rule[2]/file[13] = "/var/log/jlewis2.log"

augtool> save
error: Failed to execute command
saving failed (run 'print /augeas//error' for details)
augtool> 
augtool> print /augeas/files/etc/logrotate.d/rsyslog/error
/augeas/files/etc/logrotate.d/rsyslog/error = "put_failed"
/augeas/files/etc/logrotate.d/rsyslog/error/path = "/files/etc/logrotate.d/rsyslog/rule"
/augeas/files/etc/logrotate.d/rsyslog/error/lens = "../lenses/logrotate.aug:115.7-.58:"
/augeas/files/etc/logrotate.d/rsyslog/error/message = "Failed to match \n    { /file/ = /\\/[^\\001-\\004\\t\\n #,={}]+/ }({ /file/ = /\\/[^\\001-\\004\\t\\n #,={}]+/ })*(({ /schedule/ = /daily|weekly|monthly|yearly/ } | { /rotate/ = /[+-]?[0-9]+/ } | { /create/ } | { /nocreate/ } | { /su/ } | { /include/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /missingok/ = /(no)?missingok/ } | { /compress/ = /(no)?compress/ } | { /delaycompress/ = /(no)?delaycompress/ } | { /ifempty/ = /(not)?ifempty/ } | { /sharedscripts/ = /(no)?sharedscripts/ } | { /size/ = /[+-]?[0-9]+[GMk]?/ } | { /tabooext/ = /((\\\\+))?/ } | { /olddir/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /noolddir/ } | { /mail/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /mailfirst/ } | { /maillast/ } | { /nomail/ } | { /errors/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /extension/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /dateext/ = /(no)?dateext/ } | { /compresscmd/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /uncompresscmd/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /compressext/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /compressoptions/ } | { /copy/ = /(no)?copy/ } | { /copytruncate/ = /(no)?copytruncate/ } | { /maxage/ = /[+-]?[0-9]+/ } | { /minsize/ = /[+-]?[0-9]+[GMk]?/ } | { /shred/ = /(no)?shred/ } | { /shredcycles/ = /[+-]?[0-9]+/ } | { /start/ = /[+-]?[0-9]+/ } | { /(pre|post)rotate|(first|last)action/ = /((((([\\t ][\\t ]*e|e)ndscript[\\t ][\\t ]*[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscript[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscrip([^\\001-\\004\\nt][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscri([^\\001-\\004\\np][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscr([^\\001-\\004\\ni][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndsc([^\\001-\\004\\nr][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nds([^\\001-\\004\\nc][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nd([^\\001-\\004\\ns][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)n([^\\001-\\004\\nd][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)([^\\001-\\004\\nn][^\\001-\\004\\n]*|)|[\\t ][\\t ]*([^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)|[^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)(\\n(([\\t ][\\t ]*e|e)ndscript[\\t ][\\t ]*[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscript[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscrip([^\\001-\\004\\nt][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscri([^\\001-\\004\\np][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscr([^\\001-\\004\\ni][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndsc([^\\001-\\004\\nr][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nds([^\\001-\\004\\nc][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nd([^\\001-\\004\\ns][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)n([^\\001-\\004\\nd][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)([^\\001-\\004\\nn][^\\001-\\004\\n]*|)|[\\t ][\\t ]*([^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)|[^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|))*)?))?/ } | { /#comment/ = /[^\\001-\\004\\t\\n\\r ][^\\001-\\004\\n]*[^\\001-\\004\\t\\n\\r ]|[^\\001-\\004\\t\\n\\r ]/ })({ } | { /schedule/ = /daily|weekly|monthly|yearly/ } | { /rotate/ = /[+-]?[0-9]+/ } | { /create/ } | { /nocreate/ } | { /su/ } | { /include/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /missingok/ = /(no)?missingok/ } | { /compress/ = /(no)?compress/ } | { /delaycompress/ = /(no)?delaycompress/ } | { /ifempty/ = /(not)?ifempty/ } | { /sharedscripts/ = /(no)?sharedscripts/ } | { /size/ = /[+-]?[0-9]+[GMk]?/ } | { /tabooext/ = /((\\\\+))?/ } | { /olddir/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /noolddir/ } | { /mail/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /mailfirst/ } | { /maillast/ } | { /nomail/ } | { /errors/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /extension/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /dateext/ = /(no)?dateext/ } | { /compresscmd/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /uncompresscmd/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /compressext/ = /[^\\001-\\004\\t\\n #,={}]+/ } | { /compressoptions/ } | { /copy/ = /(no)?copy/ } | { /copytruncate/ = /(no)?copytruncate/ } | { /maxage/ = /[+-]?[0-9]+/ } | { /minsize/ = /[+-]?[0-9]+[GMk]?/ } | { /shred/ = /(no)?shred/ } | { /shredcycles/ = /[+-]?[0-9]+/ } | { /start/ = /[+-]?[0-9]+/ } | { /(pre|post)rotate|(first|last)action/ = /((((([\\t ][\\t ]*e|e)ndscript[\\t ][\\t ]*[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscript[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscrip([^\\001-\\004\\nt][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscri([^\\001-\\004\\np][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscr([^\\001-\\004\\ni][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndsc([^\\001-\\004\\nr][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nds([^\\001-\\004\\nc][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nd([^\\001-\\004\\ns][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)n([^\\001-\\004\\nd][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)([^\\001-\\004\\nn][^\\001-\\004\\n]*|)|[\\t ][\\t ]*([^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)|[^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)(\\n(([\\t ][\\t ]*e|e)ndscript[\\t ][\\t ]*[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscript[^\\001-\\004\\t\\n ][^\\001-\\004\\n]*|([\\t ][\\t ]*e|e)ndscrip([^\\001-\\004\\nt][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscri([^\\001-\\004\\np][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndscr([^\\001-\\004\\ni][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)ndsc([^\\001-\\004\\nr][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nds([^\\001-\\004\\nc][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)nd([^\\001-\\004\\ns][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)n([^\\001-\\004\\nd][^\\001-\\004\\n]*|)|([\\t ][\\t ]*e|e)([^\\001-\\004\\nn][^\\001-\\004\\n]*|)|[\\t ][\\t ]*([^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|)|[^\\001-\\004\\t\\n e][^\\001-\\004\\n]*|))*)?))?/ } | { /#comment/ = /[^\\001-\\004\\t\\n\\r ][^\\001-\\004\\n]*[^\\001-\\004\\t\\n\\r ]|[^\\001-\\004\\t\\n\\r ]/ })*)?\n  with tree\n    { \"file\" = \"/var/log/mail.info\" } { \"file\" = \"/var/log/mail.warn\" } { \"file\" = \"/var/log/mail.err\" } { \"file\" = \"/var/log/mail.log\" } { \"file\" = \"/var/log/daemon.log\" } { \"file\" = \"/var/log/kern.log\" } { \"file\" = \"/var/log/auth.log\" } { \"file\" = \"/var/log/user.log\" } { \"file\" = \"/var/log/lpr.log\" } { \"file\" = \"/var/log/cron.log\" } { \"file\" = \"/var/log/debug\" } { \"file\" = \"/var/log/messages\" } { \"rotate\" = \"4\" } { \"schedule\" = \"weekly\" } { \"missingok\" = \"missingok\" } { \"ifempty\" = \"notifempty\" } { \"compress\" = \"compress\" } { \"delaycompress\" = \"delaycompress\" } { \"sharedscripts\" = \"sharedscripts\" } { \"postrotate\" = \"\t\treload rsyslog >/dev/null 2>&1 || true\" } { \"file\" = \"/var/log/jlewis2.log\" }"
raphink commented 10 years ago

Order matters in the Augeas tree. file nodes must be the first nodes in a rule tree, so you need to insert your new file after the last one already present:

insert file after /files/etc/logrotate.d/rsyslog/*[rotate='4']/file[last()]
set /files/etc/logrotate.d/rsyslog/*[rotate='4']/file[last()] /var/log/jlewis2.log
Salokyn commented 5 years ago

Order matters in the Augeas tree. file nodes must be the first nodes in a rule tree, so you need to insert your new file after the last one already present:

insert file after /files/etc/logrotate.d/rsyslog/*[rotate='4']/file[last()]
set /files/etc/logrotate.d/rsyslog/*[rotate='4']/file[last()] /var/log/jlewis2.log

Each time you run these commands (ex: with Puppet) a new line will be added regardless it already exists.

Doing set /files/etc/logrotate.d/rsyslog/*[rotate = '4']/file[. = '/var/log/jlewis2.log'] /var/log/jlewis2.log void dupes...