Forum: Cfengine Help
Subject: templating and "Duplicate selection"
Author: bglomm
Link to topic: https://cfengine.com/forum/read.php?3,19723,19723#msg-19723

Hi all,

I have a bundle to copy a template and expand it. It works fine. But just once. 
Calling it the second time leads to a
"Duplicate selection of value for variable ..." error. I puled my hair from 
short to long but couldn't get it straight.
Must be my lack of understanding the "methods" method???

thnks 4 any hint, 

Bernhard

here comes the test code:


body common control {
    version         => "0.01";
    bundlesequence  => { "update", "snmpd_config", "snmpd_default" };
    inputs          => { "/var/lib/cfengine3/inputs/cfengine_stdlib.cf" };
}

bundle agent update{
        vars:
        "masterfiles"   string => "/srv/cfengine3/masterfiles";
        "inputs"        string => "$(masterfiles)/inputs";
        "ssh_keys"      string => "$(masterfiles)/ssh_keys";
        "cfmaster"      string => "10.0.0.99";
}


bundle agent snmpd_config {
    vars:
        any::
            "snmp2cstring"  string  =>  "notsopublic";
            "nmsaddr"       string  =>  "192.168.10.10/32";

        inhouse::
            "syslocstring"  string  =>  "here";

        outhosuse::
            "syslocstring"  string  =>  "not here";

    packages:
        "snmpd"
            comment         => "make sure snmpd is installed",
            package_policy  => "add",
            package_method  => apt;

    methods:
        "any"
            comment     =>  "snmpd.conf, we keep full control about it",
            usebundle   =>  
get_template("/etc/snmp/snmpd.conf","400","root","root");

    commands:
        restart_ur_service::
            "/etc/init.d/snmpd restart",
            comment     =>  "restart snmpd after having reconfigured 
snmpd.conf";
}

bundle agent snmpd_default {
    methods:
        "any"
            comment     =>  "/etc/default/snmpd sets the options for snmpd. 
There has to be loglevel changes for productive environment, they are quite 
static so it's easy to deploy just a fixed conffile",
            usebundle   =>  
get_template("/etc/default/snmpd","644","root","root");

    commands:
        restart_ur_service::
            "/etc/init.d/snmpd restart",
            comment     =>  "restart snmpd after having reconfigured 
snmpd.conf";
}

bundle agent get_template(final_destination,mode,owner,group) {
    vars:
        "confmasterfiles"   string => "$(update.masterfiles)/conf_files";
        "this_template"     string => lastnode("$(final_destination)","/");

    files:
        "$(final_destination).staging"
            comment => "Get template and expand variables for this host",
            perms => mog("400","root","root"),
            copy_from => 
secure_cp("$(confmasterfiles)/$(this_template)","$(update.cfmaster)"),
            action => if_elapsed("60");

        "$(final_destination)"
            comment => "Expand the template",
            create => "true",
            edit_line => expand_template("$(final_destination).staging"),
            edit_defaults => empty,
            perms => mog("$(mode)","$(owner)","$(group)"),
            action => if_elapsed("60"),
            classes => if_repaired("restart_ur_service");
}


_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to