This is a "classic" mistake (that is, everyone makes it) so don't feel badly :-)
The insert_lines promise really says "I promise that this line will be present in the file, and if it isn't, then I will insert it". So there are a few things going on here: 1) You said "insert a '{' if it is missing", so cfengine inserted it. 2) You repeated your promise (in a different place), but this time cfengine said "hey, I already did that!", so you don't get a second one 3) When you change the line with tabs and spaces, then as far as cfengine is concerned, that's a different line, so it inserts that. 4) You never specified *where* to insert lines, so they'll go at the end of your file (try deleting one of your fixed addresses, and running cf-agent and see where it gets replaced) There are a number of solutions, more or less related: 1) Use a constant file that you store somewhere and just copy. It actually takes about the same amount of effort to copy a file as it does to edit an existing one. Not as "clever" or "elegant", but a lot easier. 2) Start with a framework file, and then fill in the guts, which means you need to look at the select_region body for edit_lines (http://cfengine.com/manuals/cf3-reference.html#select_005fregion-in-_002a) 3) You can get more complicated, but why? I'd recommend solution 1. Really. The reason is that in general, only one person touches dhcpd.conf, it's a big file, and doesn't change often (so does it need to be repaired often?). Solution 2 is next, forget solution 3 :-) You have one more problem. You say: > "my_macs" string => "50:e5:49:5b:e2:be"; > "my_macs" string => "00:1e:8f:79:ac:e9"; > "my_macs" string => "a8:e3:ee:02:dc:58"; And that is redefining a string - not what you wanted. I think you wanted to say something more like > "my_macs[foo]" string => "50:e5:49:5b:e2:be"; > "my_macs[baz]" string => "00:1e:8f:79:ac:e9"; > "my_macs[gar]" string => "a8:e3:ee:02:dc:58"; And the same thing for my_ips. -Dan On Jan 11, 2012, at 6:36 AM, no-re...@cfengine.com wrote: > Forum: CFEngine Help > Subject: insert line: bug ?? > Author: stchesmeli > Link to topic: https://cfengine.com/forum/read.php?3,24539,24539#msg-24539 > > Hello all, > > i'm wondering if there is a bug in insert line.... let me explain > > I'm trying to build my dhcpd.conf with list of host and array of macs and ips. > My code: > > > bundle common icebox_lan > { > vars: > "my_macs" string => "50:e5:49:5b:e2:be"; > "my_macs" string => "00:1e:8f:79:ac:e9"; > "my_macs" string => "a8:e3:ee:02:dc:58"; > "my_macs" string => "7c:61:93:8d:93:b8"; > "my_macs" string => "00:19:1d:fd:55:b0"; > "my_macs" string => "00:24:d6:87:18:80"; > "my_macs" string => "00:26:b9:d2:ce:aa"; > "my_macs" string => "4c:0f:6e:d4:c2:29"; > "my_macs" string => "e8:5b:5b:c1:17:86"; > "my_macs" string => "00:26:4d:a5:d3:68"; > "my_macs" string => "00:27:0e:07:61:a0"; > "my_macs" string => "e8:be:81:2c:27:59"; > > "my_ips" string => "192.168.50.10"; > "my_ips" string => "192.168.50.40"; > "my_ips" string => "192.168.50.18"; > "my_ips" string => "192.168.50.19"; > "my_ips" string => "192.168.50.25"; > "my_ips" string => "192.168.50.50"; > "my_ips" string => "192.168.50.51"; > "my_ips" string => "192.168.50.20"; > "my_ips" string => "192.168.50.30"; > "my_ips" string => "192.168.50.31"; > "my_ips" string => "192.168.50.254"; > "my_ips" string => "192.168.50.1"; > > "my_hosts" slist => getindices("my_macs"); > "my_domain" string => "icebox.lan"; > "my_router" string => "$(my_ips)"; > "my_ns1" string => "$(my_ips)"; > "my_ns2" string => "$(my_ips)"; > } > > bundle common goldorak_conf > { > vars: > "pkg_dhcpd" string => "isc-dhcp-server"; > } > > bundle agent set_goldo_dhcp_server > { > vars: > "my_dhcdp_options" string => > "ddns-update-style none; > log-facility local7; > > "; > > "my_share_network" string => > "shared-network home > { > subnet 192.168.50.0 netmask 255.255.255.0 { > option domain-name \"$(icebox_lan.my_domain)\"; > option domain-name-servers $(icebox_lan.my_ns1), $(icebox_lan.my_ns2); > option routers $(icebox_lan.my_router); > default-lease-time 600; > max-lease-time 7200; > } > > subnet 10.0.0.0 netmask 255.255.255.0 { > option domain-name \"blackhole.lan\"; > option domain-name-servers 10.0.0.1; > option routers 10.0.0.1; > range 10.0.0.10 10.0.0.250; > default-lease-time 600; > max-lease-time 7200; > } > } > "; > packages: > "$(goldorak_conf.pkg_dhcpd)" > package_policy => "add", > package_method => generic, > classes => if_repaired("dhcpd_installed"); > files: > "/etc/dhcp/dhcpd.conf" > comment => "Set the dhcpd configuration", > edit_line => dhcpdconf(${my_dhcdp_options}, ${my_share_network}, > @(icebox_lan.my_hosts), "icebox_lan.my_macs", "icebox_lan.my_ips" ), > create => "true", > edit_defaults => empty, > perms => mog("644","root","root"), > classes => if_repaired("dhcpd_repaired"); > processes: > "/usr/sbin/dhcpd" > restart_class => "restart_dhcpd"; > commands: > dhcpd_installed:: > "/usr/sbin/update-rc.d $(goldorak_conf.pkg_dhcpd) defaults"; > dhcpd_repaired|restart_dhcpd:: > "/etc/init.d/isc-dhcp-server restart"; > } > > bundle edit_line dhcpdconf(doptions,dnetwork,dhosts, dmacs, dips) > { > > insert_lines: > "$(doptions) > $(dnetwork)"; > "host $(dhosts) { $(const.n) $(const.t) hardware ethernet > $($(dmacs)[$(dhosts)]); $(const.n) $(const.t) fixed-address > $($(dips)$(dhosts)]); $(const.n) }"; > > } > > > > my output dhcpd.conf generated: > > > ddns-update-style none; > log-facility local7; > > > shared-network home > { > subnet 192.168.50.0 netmask 255.255.255.0 { > option domain-name "icebox.lan"; > option domain-name-servers 192.168.50.254, 192.168.50.1; > option routers 192.168.50.254; > default-lease-time 600; > max-lease-time 7200; > } > > subnet 10.0.0.0 netmask 255.255.255.0 { > option domain-name "blackhole.lan"; > option domain-name-servers 10.0.0.1; > option routers 10.0.0.1; > range 10.0.0.10 10.0.0.250; > default-lease-time 600; > max-lease-time 7200; > } > } > > host lg-wifi { > hardware ethernet 00:26:4d:a5:d3:68; > fixed-address 192.168.50.31; > } > host livebox { > hardware ethernet e8:be:81:2c:27:59; > fixed-address 192.168.50.1; > host vaio { > hardware ethernet 4c:0f:6e:d4:c2:29; > fixed-address 192.168.50.20; > host goldorak { > hardware ethernet 00:27:0e:07:61:a0; > fixed-address 192.168.50.254; > host ps3 { > hardware ethernet a8:e3:ee:02:dc:58; > fixed-address 192.168.50.18; > host wii { > hardware ethernet 00:19:1d:fd:55:b0; > fixed-address 192.168.50.25; > host dell { > hardware ethernet 00:24:d6:87:18:80; > fixed-address 192.168.50.50; > host mp620 { > hardware ethernet 00:1e:8f:79:ac:e9; > fixed-address 192.168.50.40; > host dell-eth { > hardware ethernet 00:26:b9:d2:ce:aa; > fixed-address 192.168.50.51; > host aziz { > hardware ethernet 50:e5:49:5b:e2:be; > fixed-address 192.168.50.10; > host htc { > hardware ethernet 7c:61:93:8d:93:b8; > fixed-address 192.168.50.19; > host lg { > hardware ethernet e8:5b:5b:c1:17:86; > fixed-address 192.168.50.30; > > > As you see, the first host entry is ok: > > > host lg-wifi { > hardware ethernet 00:26:4d:a5:d3:68; > fixed-address 192.168.50.31; > } > > > But the next not: > > > host livebox { > hardware ethernet e8:be:81:2c:27:59; > fixed-address 192.168.50.1; > > missing the last line with " }". I don't understand why... > And when i change the insert line, insert space for example, or changing > $(const.n) or $(const.t) with the real "enter" or "tab" sometime the line is > ok !! ... > > My cfengine version: 3.2.1 > Official package for ubuntu 11.10 from cfengine website. > > _______________________________________________ > 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