Hello all, My next task is to fill in some template files. These require various values to be filled in but not values directly known to facter or puppet. For example I am configuing a mysql slave server and this requires a unique server-id field to be filled in. server-id = <some number> Our convention is to do the following: from a given interface find out the ip address and then use the last 3 bytes to generate the id. The simple script to do this is shown below: ------ #!/bin/sh INTERFACE=$1 echo "Interface: $INTERFACE" IP=$(/sbin/ifconfig $INTERFACE | grep "inet addr:" |awk ''{ print $2 }'' | sed -e ''s/.*://'') echo "ip address: $IP" # we want to convert the last 3 digits into a numeric value set -- `echo $IP | sed ''s/\./ /g''` MYSQL_ID=`printf "%03d%03d%03d" $2 $3 $4` echo "MYSQL_ID: $MYSQL_ID" ------ Thus: $ sh myscript eth0 Interface: eth0 ip address: 192.168.0.2 MYSQL_ID: 168000002 So how can I fill a puppet variable $mysql_id with the results of a script like this in order to use it later when building the configuration file from a template? Thanks again for any pointers on how this can be done. Regards, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi> So how can I fill a puppet variable $mysql_id with the results of a script > like this in order to use it later when building the configuration file > from a template?write a custom fact, which you can use in the template. greets 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 -~----------~----~----~----~------~----~------~--~---
Peter Meier wrote:>> So how can I fill a puppet variable $mysql_id with the results of a script >> like this in order to use it later when building the configuration file >> from a template? > > write a custom fact, which you can use in the template.If you only need it in that particular template file, and not in dozens of other places, it is probably easier to put the code that reformats the IP address in that template. Something like <% i1,i2,i3,i4 = ipaddress.split(''.'') serverid = sprintf(''%03d%03d%03d'', i2, i3, i4) %> should do it. /Thomas 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 Thu, 29 May 2008 17:35:25 Thomas wrote:> Peter Meier wrote: > > >> So how can I fill a puppet variable $mysql_id with the results of a script > >> like this in order to use it later when building the configuration file > >> from a template? > > > > write a custom fact, which you can use in the template.That''s no use as I only want to do this for a specific interface (which I choose). Creating a custom fact for all interfaces seems silly as normally only one will be used. However I''ve just seen the generate() function which may be closer to what I want.> If you only need it in that particular template file, and not in > dozens of other places, it is probably easier to put the code that > reformats the IP address in that template. Something like > > <% > i1,i2,i3,i4 = ipaddress.split(''.'') > serverid = sprintf(''%03d%03d%03d'', i2, i3, i4) > %>This is the other way and obviously requires me learning Ruby. I had hoped to escape this but guess I need to take a trip down to the bookshop and start reading... Thanks for the idea though. In my case the interface while normally the same may vary so it can''t be hard-coded in the template file. Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > However I''ve just seen the generate() function which may be closer to what I > want. >Probably not what you want. The generate() function only runs one the server not on the client. This true of all the functions. Evan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---