Are there any such things? For example $ip_list_arr=split(ip_list,",") $ip_external=*$ip_list_arr[0]* Or the only way to do it, is via custom functions? I think I read something like this before, but can''t remember where or if it was with a custom function or not. Silviu -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Silviu Paragina wrote:> Are there any such things? For example > $ip_list_arr=split(ip_list,",") > $ip_external=*$ip_list_arr[0]* > > Or the only way to do it, is via custom functions? > I think I read something like this before, but can''t remember where or > if it was with a custom function or not.Not at the moment. There is some work being done to add hashes to the Puppet language, and then I think we will get array indexing at the same time. If you only need it once, you can abuse inline_template() to do it: $ip_list_arr = split($ip_list, ",") $ip_external = inline_template("<%= ip_list_arr[0] %>") Or, for this specific case, where you start by splitting a string, you can use regsubst(): $ip_external = regsubst($ip_list, "^([^,]*).*", "\\1") /Bellman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 02.12.2009 17:39, Thomas Bellman wrote:> Silviu Paragina wrote: > > >> Are there any such things? For example >> $ip_list_arr=split(ip_list,",") >> $ip_external=*$ip_list_arr[0]* >> >> Or the only way to do it, is via custom functions? >> I think I read something like this before, but can''t remember where or >> if it was with a custom function or not. >> > Not at the moment. There is some work being done to add hashes to > the Puppet language, and then I think we will get array indexing at > the same time. > > If you only need it once, you can abuse inline_template() to do it: > > $ip_list_arr = split($ip_list, ",") > $ip_external = inline_template("<%= ip_list_arr[0] %>") >What do you mean by once? It''s slow? Or some other reason? I need to get the first item, then the second, and if the second is not there pass the first. (ip_list is a custom fact that lists the machines ip addresses sorted, except 127.0.0.1) :-? I think it might be better for my case to define the custom facts as iplist_1, iplist_2. But I''m not sure what are the downsides of using inline_template, if there are next to none I think I''ll use it. Thank you for the quick reply and info. :)> Or, for this specific case, where you start by splitting a string, you > can use regsubst(): > > $ip_external = regsubst($ip_list, "^([^,]*).*", "\\1") > > > /Bellman > > -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > > >Silviu -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Silviu Paragina wrote:> On 02.12.2009 17:39, Thomas Bellman wrote:>> If you only need it once, you can abuse inline_template() to do it: >> >> $ip_list_arr = split($ip_list, ",") >> $ip_external = inline_template("<%= ip_list_arr[0] %>")> What do you mean by once? It''s slow? Or some other reason?The reason is that it''s an ugly hack. Each place in your manifests that you use something like the above construct, will cause some pain in those who read the manifests when they see the ugliness. So, how many times do you want to inflict that pain on your fellow sysadmins? :-) /Bellman -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
> What do you mean by once? It''s slow? Or some other reason? > I need to get the first item, then the second, and if the second is not > there pass the first. > (ip_list is a custom fact that lists the machines ip addresses sorted, > except 127.0.0.1)if you already have custom facts, why not do the decision in another custom fact, which is based on the output on the ip_list fact and which does this logic for you? cheers pete -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 02.12.2009 18:27, Peter Meier wrote:>> What do you mean by once? It''s slow? Or some other reason? >> I need to get the first item, then the second, and if the second is not >> there pass the first. >> (ip_list is a custom fact that lists the machines ip addresses sorted, >> except 127.0.0.1) >> > if you already have custom facts, why not do the decision in another > custom fact, which is based on the output on the ip_list fact and > which does this logic for you? > > cheers pete > >I wanted the facts to be general. IE reuse this if I need a setup with 3 ips. The current requirement is for a website deployed on 2 ips on the production machine. Because the development machine has only one ip, I wanted the vhosts deployed only on that one ip. Before this testing/development meant I had to modify the files to work on the testing machine, make the actual changes, test, then copy only the required changes to puppet. But this is error prone... Thanks for the support, I think that if I would of done this alone, without asking, I would of implemented a function to access the members of the array, which seems a bit too complicated just for this. Cheers and thanks again for the support, :) Silviu> -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Silviu Paragina wrote:> (ip_list is a custom fact that lists the machines ip addresses sorted, > except 127.0.0.1) >Could you post more of the manifest? You might be able to use the interfaces fact instead of writing your own: scott@dongle:~% for iface in `facter | egrep -e ''^interfaces'' | awk ''{ print $3 }''` do facter | egrep -e "(ipaddress|macaddress|netmask|network)_$iface" done ipaddress_eth0 => 10.15.50.36 macaddress_eth0 => 00:23:ae:98:02:b5 netmask_eth0 => 255.255.255.0 network_eth0 => 10.15.50.0 scott@dongle:~% Maybe it won''t help in your case, but it could at least reduce the amount of code you write/debug :) -scott -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On 03.12.2009 19:07, Scott Smith wrote:> Silviu Paragina wrote: > >> (ip_list is a custom fact that lists the machines ip addresses sorted, >> except 127.0.0.1) >> >> > Could you post more of the manifest? You might be able to use the > interfaces fact instead of writing your own: > > scott@dongle:~% for iface in `facter | egrep -e ''^interfaces'' | awk ''{ > print $3 }''` > do > facter | egrep -e "(ipaddress|macaddress|netmask|network)_$iface" > done > ipaddress_eth0 => 10.15.50.36 > macaddress_eth0 => 00:23:ae:98:02:b5 > netmask_eth0 => 255.255.255.0 > network_eth0 => 10.15.50.0 > scott@dongle:~% > > Maybe it won''t help in your case, but it could at least reduce the > amount of code you write/debug :) > > -scott > > -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > > >I have already implemented the fact, templates and manifests :-) . If anyone requires the facter plugin I''ll attach it on the list. The templates control the ips some nginx vhosts bind to. Leaving that aside for the sake of the discussion, it would be harder to do it via puppet and interfaces because the production machine is actually a vps (openvz). Facter says this on my vps ipaddress => xx.xx.xx.1 ipaddress_venet0 => 127.0.0.1 ipaddress_venet0_0 => xx.xx.xx.1 ipaddress_venet0_1 => xx.xx.xx.2 And of course on the development machine, being a real machine, the output is similar to your output. As I want to be able to apply this manifest on both a real machine and a virtual one, it''s kind of hard to do it with only the default facts. Silviu -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.