I'm using the first solution, but I'm getting and error with the always clause:
No such FnCall "always()" in promise @ /var/cfengine/git/check-file-perms.cfnear line 384 Not sure where I should have defined the always function, in my library.cf ? ....................... more file .......................... "/etc/hosts.testing" edit_line => replace_or_add(".*\s+rxodb", "1.2.3.4 rxodb rxodb.com"), perms => mog("600","root","root"), changes => lay_a_tripwire; } bundle edit_line replace_or_add(pattern,line) { replace_patterns: "^${pattern}$" replace_with => value("${line}"), classes => always("replace_done"); insert_lines: replace_done:: "${line}"; } cf3 !! File /etc/hosts.testing was not in md5 database - new file found cf3 I: Report relates to a promise with handle "" cf3 I: Made in version 'not specified' of '/var/cfengine/git/ check-file-perms.cf' near line 372 cf3 -> Object /etc/hosts.testing had permission 444, changed it to 600 cf3 -> Handling file existence constraints on /etc/hosts.testing cf3 -> File permissions on /etc/hosts.testing as promised cf3 -> Handling file edits in edit_line bundle replace_or_add cf3 cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 BUNDLE replace_or_add( {'.*\s+rxfordb','1.2.3.4 rxfordb rxfordb.mdef.es'} ) cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * cf3 cf3 ? Augment scope replace_or_add with pattern cf3 ? Augment scope replace_or_add with line cf3 ?? Private class context cf3 cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 insert_lines in bundle replace_or_add cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 cf3 . . . . . . . . . . . . . . . cf3 Skipping whole next edit promise, as context replace_done is not relevant cf3 . . . . . . . . . . . . . . . cf3 cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 replace_patterns in bundle replace_or_add cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = cf3 cf3 No such FnCall "always()" in promise @ /var/cfengine/git/ check-file-perms.cf near line 384 cf3 cf3 ......................................................... cf3 Promise handle: cf3 Promise made by: ^.*\s+rxfordb$ cf3 ......................................................... cf3 cf3 -> Looking at pattern ^.*\s+rxfordb$ cf3 Software error - expected type (X) for boolean constraint classes did not match internals cf3 Fatal cfengine error: Aborted cf3 Outcome of version (not specified) (agent-0): Promises observed to be kept 95%, Promises repaired 5%, Promises not repaired 0% On Wed, Mar 17, 2010 at 7:15 PM, Diego Zamboni <di...@zzamboni.org> wrote: > Daniel, > > I have been working on a similar problem, and came up with the > following two bundles for editing files. I think both of these could > be used to edit an /etc/hosts file, one by passing the pattern, e.g. > > edit_line => replace_or_add(".*\s+hostname", "1.2.3.4 hostname") > # 1.2.3.4 is the new IP address > > The second one can't be used as-is since the value you want to change > (the IP address) is in the first field, I think the necessary change > would be to change the "2" to "1" in the second call to col(), and > maybe some other changes, I think this could certainly be used as a > starting point. > > Cheers, > --Diego > > > # Replace a pattern in a file with a single line. > # If the pattern is not found, add the line to the file. > # The pattern must match the whole line (it is automatically > # anchored to the start and end of the line) to avoid > # ambiguity. > bundle edit_line replace_or_add(pattern,line) > { > replace_patterns: > "^${pattern}$" > replace_with => value("${line}"), > classes => always("replace_done"); > > insert_lines: > replace_done:: > "${line}"; > } > > # Sets the RHS of configuration items in the file of the form > # LHS RHS > # If the line is commented out with #, it gets uncommented first > # Adds a new line if non exists. > # The argument is an associative array containint v[LHS]="rhs" > > # Based on set_variable_values from cfengine_stdlib.cf, modified > # by Diego Zamboni to use whitespace as separator, and to handle > # commented-out lines. > bundle edit_line set_config_values(v) > { > vars: > "index" slist => getindices("$(v)"); > > # Be careful if the index string contains funny chars > "cindex[$(index)]" string => canonify("$(index)"); > > field_edits: > > # If the line is there, but commented out, first uncomment it > "#+$(index)\s+.*" > edit_field => col("\s+","1","$(index)","set"); > > # match a line starting like the key something > "$(index)\s+.*" > edit_field => col("\s+","2","$($(v)[$(index)])","set"), > classes => if_ok("not_$(cindex[$(index)])"); > > insert_lines: > > "$(index) $($(v)[$(index)])", > ifvarclass => "!not_$(cindex[$(index)])"; > } > > > > On Wed, Mar 17, 2010 at 11:43 AM, daniel parkes <liquidsm...@gmail.com> > wrote: > > Hi, > > > > We have a very large /etc/hosts(300 hosts) files in our servers that we > have > > to mantain for certain acient applications, as of now what I have > configured > > in cfengine 3.0.2 is an edit line bundle that reads from a master host > file > > and if the host isn't in the file it adds it. > > > > The problem is just and add line, if I modify one of the hosts ip address > it > > won't replace it with the new one, it just adds the line at the end. > > > > I have been triying to get it working with replace_with and regex > > expresions, but I really can't find a way to do it easily, any of you > doing > > something like this could get me started ?? > > > > I'cant paste the code I am using because i'm not at work, but I will get > in > > tomorrow. > > > > Thnx for the help > > > > _______________________________________________ > > 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