First of all, thank you for the self-contained example! That helps a lot. As far as I can tell, you have found a bug (but also a mistake in your interpretation). Your pattern wont match in the string "enabled = 00", but not because you only have a single 0 (it's because the first "0 doesn't match the "[^0]"). By the same measure, "\d" does match in the string "1234" (in fact, "\d*" matches in the string "hello", because "hello" has zero or more consecutive digits in it :-).
And you're right, you shouldn't need a '$' at the end of your pattern. That said, your example ought to work, and it ought not raise a complaint. AFAICT, you found a bug. It looks like an "off by one" error somewhere to me, but I can't tell where... If you want a workaround, look at "set_variable_values" in the COPBL -Dan On Nov 19, 2010, at 2:20 PM, no-re...@cfengine.com wrote: > Forum: Cfengine Help > Subject: replace_patterns bug? > Author: babudro > Link to topic: https://cfengine.com/forum/read.php?3,19347,19347#msg-19347 > > Hello Cfengineers. > > Like Michael Potter's post on 9 November, I am also running into some strange > behaviour with replace_patterns. I wonder if someone can spot if I am doing > something wrong so I don't file an erroneous bug report. > > All I am trying to do is replace a parameter line in a file. I created this > rule to toggle the setting: > > > bundle edit_line yum_plugins(x) { > replace_patterns: > "^enabled\s*=\s*[^$(x)]" replace_with => value("enabled = $(x)"); > } > > > The idea is that if I pass x=0 then it searches for "enabled" not equal to > zero and, if it finds a match, changes it to be zero. > > When I run this promise, I get this: > > > -> Promised replacement "enabled = 00000000000000000000" on line "enabled = > 1" for pattern "^enabled\s*=\s*[^0]" is not convergent while editing > /etc/yum/pluginconf.d/rhnplugin.conf > Because the regular expression "^enabled\s*=\s*[^0]" still matches the > replacement string "enabled = 00000000000000000000" > Promise (version 8) belongs to bundle 'yum_plugins' in file './yum.cf' near > line 215 > -> Promised replacement "enabled = 00000000000000000000" on line "enabled = > 1" for pattern "^enabled\s*=\s*[^0]" is not convergent while editing > /etc/yum/pluginconf.d/rhnplugin.conf > > > How weird is that? I understand how "enabled = 00" does not match the > pattern "^enabled\s*=\s*[^0]" since I only have a single zero, but how did it > ever get that second (and third and fourth &c.) zero? It should have made > the first replacement and then stopped since the match is no longer true. > > If I put a dollar-sign at the end of the match string, it works. But I > shouldn't have to do that. > > Am I missing something? > > Here is a self-contained policy file to demonstrate this apparent bug: > > > body common control { > bundlesequence => { "yum" }; > } > bundle agent yum { > files: > redhat:: > "/tmp/test.conf" > comment => "Demonstrate pattern bug", > create => "false", > edit_line => yum_plugins("0"); > > reports: > plugins_toggled:: > "Toggled 'enabled' flag in test.conf."; > } > bundle edit_line yum_plugins(x) { > replace_patterns: > "^enabled\s*=\s*[^$(x)]" replace_with => value("enabled = $(x)"); > } > body replace_with value(x) { > replace_value => "$(x)"; > occurrences => "all"; > } > > # vim:ts=2 > > > Create the file /tmp/test.conf with just this one line: > > > enabled = 1 > > > Now watch it explode: > > > $ cf-agent -f ./pattern_bug.cf > -> Promised replacement "enabled = 00000000000000000000" on line "enabled = > 1" for pattern "^enabled\s*=\s*[^0]" is not convergent while editing > /tmp/test.conf > I: Made in version 'not specified' of './pattern_bug.cf' near line 18 > Because the regular expression "^enabled\s*=\s*[^0]" still matches the > replacement string "enabled = 00000000000000000000" > Promise (version not specified) belongs to bundle 'yum_plugins' in file > './pattern_bug.cf' near line 18 > -> Promised replacement "enabled = 00000000000000000000" on line "enabled = > 1" for pattern "^enabled\s*=\s*[^0]" is not convergent while editing > /tmp/test.conf > I: Made in version 'not specified' of './pattern_bug.cf' near line 18 > Because the regular expression "^enabled\s*=\s*[^0]" still matches the > replacement string "enabled = 00000000000000000000" > Promise (version not specified) belongs to bundle 'yum_plugins' in file > './pattern_bug.cf' near line 18 > -> Promised replacement "enabled = 00000000000000000000" on line "enabled = > 1" for pattern "^enabled\s*=\s*[^0]" is not convergent while editing > /tmp/test.conf > I: Made in version 'not specified' of './pattern_bug.cf' near line 18 > Because the regular expression "^enabled\s*=\s*[^0]" still matches the > replacement string "enabled = 00000000000000000000" > Promise (version not specified) belongs to bundle 'yum_plugins' in file > './pattern_bug.cf' near line 18 > > > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine