In general, take a look at whitespace_policy in insert_lines for some ideas...  
Also look at set_variable_values in cfengine_stdlib.cf for others

-Dan

On May 20, 2011, at 3:16 PM, no-re...@cfengine.com wrote:

> Forum: Cfengine Help
> Subject: Re: Cfengine Help: question about editing smb.conf
> Author: raymondcox
> Link to topic: https://cfengine.com/forum/read.php?3,22090,22108#msg-22108
> 
> I would like to change the following entries in smb.conf
> 
> Each entry is preceded by a tab
> 
>        workgroup = MYGROUP
>        security = domain
>        realm = MY_REALM
> 
>        password server = 
> 
> I have the following field_edits defined:
> 
> body common control {
> 
>    bundlesequence => { "smbcfgfiles" };
>            inputs => { "../cfengine_stdlib.cf", "../library.cf", };
> }
> 
> bundle agent smbcfgfiles
> {
> vars:
>  "smbconfig" string => "/tmp/smb.conf";
> 
>  # smb configuration to set
>  "smb"                        string => " test";
>  "smb"                  string => " testdc.example.com";
>  "smb"                            string => " EXAMPLE.COM";
>  "smb"                         string => " ads";
> 
> methods:
>  "smb"    usebundle => edit_smb("$(smbconfig)", "smbcfgfiles.smb");
> }
> 
> bundle agent edit_smb(file,params)
> {
> files:
>  "$(file)"
>  handle => "edit_smb",
>  comment => "Set desired /etc/samba/smb.conf parameters",
>  edit_line => set_smb_values("$(params)");
> 
> }
> 
> bundle edit_line set_smb_values(v)
> 
> 
> {
> vars:
> 
>  "index" slist => getindices("$(v)");
> 
>  # Be careful if the index string contains funny chars
> 
>  "cindex[$(index)]" string => canonify("$(index)");
> 
> field_edits:
> 
>  # match a line starting like the key = something
> 
>  "\t*$(index)\s*=.*"
> 
>     edit_field => col("=","2","$($(v)[$(index)])","set"),
>        classes => if_ok("$(cindex[$(index)])_in_file"),
>        comment => "Match a line starting like key = something";
> 
> insert_lines:
> 
>  "$(index)=$($(v)[$(index)])",
> 
>         comment => "Insert a variable definition",
>      ifvarclass => "!$(cindex[$(index)])_in_file";
> }
> 
> 
> 
> Which produces:
> 
>        workgroup = test
>        security = ads
>        realm = EXAMPLE.COM
> 
>        password server = 
> passwor=$(smbcfgfiles.smb)
> 
> I suspect the field_edits method is not well suited for this task, however I 
> am not exactly sure of what the best method to use in this instance is.
> 
> Thank you for your 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

Reply via email to