On 03/05/2012 04:33 PM, Daniel V. Klein wrote: > It is pretty hard to determine what you did wrong when you haven't shared > what you did...
Well I included a gist link to the code. But Aleksey also commented that replace_or_add wasn't included in it, so I have attached the example policy and in-lined all of the parts from the stdlib that are required. -- Nick Anderson <n...@cmdln.org>
body common control { bundlesequence => { "main", }; } bundle agent main { methods: "any" usebundle => rh_set_hostname("node1", "domain.com"); } bundle agent rh_set_hostname(hostname, domainname){ # Expects desired shorthostname and domain name both as strings; # Usage: # vars: # "hostname" string => "jim"; # "domain" string => "bob.com"; # # methods: # "hostname" usebundle => rh_set_hostname("$(hostname)", "$(domain)"); # files: "/tmp/network" edit_line => replace_or_add("HOSTNAME=.*", "HOSTNAME=$(hostname)"), classes => if_repaired("update_running_hostname"), comment => "Redhat docs are WRONG, if you set this to fqdn it will cause the hostname command to return the fqdn instead of the shorthostname"; "/tmp/network" edit_line => replace_or_add("NISDOMAIN=.*", "NISDOMAIN=$(domainname)"), classes => if_repaired("update_running_hostname"), comment => "Set the domainname"; } ########################################################################### # From Stdlib # ########################################################################### bundle edit_line replace_or_add(pattern,line) # 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. { vars: "cline" string => canonify("$(line)"); replace_patterns: "^(?!$(line))$(pattern)$" replace_with => value("$(line)"), classes => always("replace_done_$(cline)"); insert_lines: "$(line)" ifvarclass => "replace_done_$(cline)"; } body classes always(x) # Define a class no matter what the outcome of the promise is { promise_repaired => { "$(x)" }; promise_kept => { "$(x)" }; repair_failed => { "$(x)" }; repair_denied => { "$(x)" }; repair_timeout => { "$(x)" }; } body replace_with value(x) { replace_value => "$(x)"; occurrences => "all"; } body classes if_repaired(x) { promise_repaired => { "$(x)" }; }
_______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine