I hope my title makes sense. I''m still new to puppet but have made a lot o progress in a matter of 2-3 days and have a good grasp on the fundamentals... Now I''m trying to determine how to do a little more then basic things. My hosts all have standard hosts files that are almost identical, what''s not identical is 3 lines, 2 lines I can generate with ip address information and hostname, the third line I can pull from an outside db or from the existing file. i.e.: custom host entries: 192.168.1.20 host1.domain.com 192.168.1.30 host2.domain.com 192.168.1.250 unique_host.domain.com Is there a way to manage this with puppet? What I would like to do is be able to check that those 3 entries exist... if not replace the file and generate the custom content that needs to be in the file? Not sure how to do this in puppet.. or if it is even possible. My thought''s are a custom script that verifies the file, if that script fails... replace the file, then run another script to populate the custom information. Or can this all be done from within puppet? Also the hosts file is just an example... I have probably a dozen other files I need to be able to do this with. -- 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.
Dan Bode
2011-Jan-09 19:01 UTC
Re: [Puppet Users] pushing files with host based variables?
On Sun, Jan 9, 2011 at 10:42 AM, trey85stang <trey85stang@gmail.com> wrote:> I hope my title makes sense. I''m still new to puppet but have made a > lot o progress in a matter of 2-3 days and have a good grasp on the > fundamentals... Now I''m trying to determine how to do a little more > then basic things. > > My hosts all have standard hosts files that are almost identical, > what''s not identical is 3 lines, 2 lines I can generate with ip > address information and hostname, the third line I can pull from an > outside db or from the existing file. > > i.e.: > > custom host entries: > > 192.168.1.20 host1.domain.com > 192.168.1.30 host2.domain.com > 192.168.1.250 unique_host.domain.com > > Is there a way to manage this with puppet?It sounds like something you can do with the host resource type. It can specify individual lines of /etc/hosts as resources.> What I would like to do is > be able to check that those 3 entries exist... if not replace the file > and generate the custom content that needs to be in the file? >so you want to transform the host files based on their current state? The only way to get system specific information to make determinations during compile time would be with a custom fact. This feels a little ugly though. I have a feeling I am not understanding your requirements though.> Not sure how to do this in puppet.. or if it is even possible. > > My thought''s are a custom script that verifies the file, if that > script fails... replace the file,It is not very easy to model things like this in Puppet. With Puppet you want to specify the end states of things, you should try to model it with that in mind.> then run another script to populate > the custom information. Or can this all be done from within puppet? > Also the hosts file is just an example... I have probably a dozen > other files I need to be able to do this with. >feel free to ping me on irc, might be a little easier to understand what you mean synchronously - bodepd<at>freenode.net> -- > 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<puppet-users%2Bunsubscribe@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.
Bruce Richardson
2011-Jan-10 10:35 UTC
Re: [Puppet Users] pushing files with host based variables?
On Sun, Jan 09, 2011 at 10:42:19AM -0800, trey85stang wrote:> > 192.168.1.20 host1.domain.com > 192.168.1.30 host2.domain.com > 192.168.1.250 unique_host.domain.com > > Is there a way to manage this with puppet? What I would like to do is > be able to check that those 3 entries exist... if not replace the file > and generate the custom content that needs to be in the file?If you use host resources, as already recommended, Puppet will create the entries if they do not exist. If you only want those entries present, tell Puppet to purge all host entries not specified in the puppet configuration for that host. host { ''host1.domain.com'': ip => ''192.168.1.20'', ensure => ''present'' } host { ''host2.domain.com'': ip => ''192.168.1.30'', ensure => ''present'' } host { ''unique_host.domain.com'': ip => ''192.168.1.250'', ensure => ''present'' } resources { ''host'': purge => true } Stop thinking custom scripts; start thinking resources. Most Puppet configuration consists of specifying which resources you do or don''t want present in which circumstances. Most of the rest of it is about defining which resources depend on which others (e.g. this running application depends on that configuration file). You describe how a system should look and Puppet does what is necessary to make it so. -- Bruce I object to intellect without discipline. I object to power without constructive purpose. -- Spock -- 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.
trey85stang
2011-Jan-10 15:56 UTC
[Puppet Users] Re: pushing files with host based variables?
Thanks for the reply, It looks like I would need an entry for every host if I were to take that route? My environment would require 6000*3 entries... That doesn''t seem logical. Am I understanding this correctly? On Jan 10, 4:35 am, Bruce Richardson <itsbr...@workshy.org> wrote:> On Sun, Jan 09, 2011 at 10:42:19AM -0800, trey85stang wrote: > > > 192.168.1.20 host1.domain.com > > 192.168.1.30 host2.domain.com > > 192.168.1.250 unique_host.domain.com > > > Is there a way to manage this with puppet? What I would like to do is > > be able to check that those 3 entries exist... if not replace the file > > and generate the custom content that needs to be in the file? > > If you use host resources, as already recommended, Puppet will create > the entries if they do not exist. If you only want those entries > present, tell Puppet to purge all host entries not specified in the > puppet configuration for that host. > > host { ''host1.domain.com'': > ip => ''192.168.1.20'', > ensure => ''present'' > } > > host { ''host2.domain.com'': > ip => ''192.168.1.30'', > ensure => ''present'' > } > > host { ''unique_host.domain.com'': > ip => ''192.168.1.250'', > ensure => ''present'' > } > > resources { ''host'': purge => true } > > Stop thinking custom scripts; start thinking resources. Most Puppet > configuration consists of specifying which resources you do or don''t > want present in which circumstances. Most of the rest of it is about > defining which resources depend on which others (e.g. this running > application depends on that configuration file). You describe how a > system should look and Puppet does what is necessary to make it so. > > -- > Bruce > > I object to intellect without discipline. I object to power without > constructive purpose. -- Spock-- 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.
trey85stang
2011-Jan-10 16:09 UTC
[Puppet Users] Re: pushing files with host based variables?
Actually, upon more reading on my own, this is where stored configs will come into play? Ill approach more reading on that subject. On Jan 10, 9:56 am, trey85stang <trey85st...@gmail.com> wrote:> Thanks for the reply, > > It looks like I would need an entry for every host if I were to take > that route? My environment would require 6000*3 entries... That > doesn''t seem logical. > > Am I understanding this correctly? > > On Jan 10, 4:35 am, Bruce Richardson <itsbr...@workshy.org> wrote: > > > On Sun, Jan 09, 2011 at 10:42:19AM -0800, trey85stang wrote: > > > > 192.168.1.20 host1.domain.com > > > 192.168.1.30 host2.domain.com > > > 192.168.1.250 unique_host.domain.com > > > > Is there a way to manage this with puppet? What I would like to do is > > > be able to check that those 3 entries exist... if not replace the file > > > and generate the custom content that needs to be in the file? > > > If you use host resources, as already recommended, Puppet will create > > the entries if they do not exist. If you only want those entries > > present, tell Puppet to purge all host entries not specified in the > > puppet configuration for that host. > > > host { ''host1.domain.com'': > > ip => ''192.168.1.20'', > > ensure => ''present'' > > } > > > host { ''host2.domain.com'': > > ip => ''192.168.1.30'', > > ensure => ''present'' > > } > > > host { ''unique_host.domain.com'': > > ip => ''192.168.1.250'', > > ensure => ''present'' > > } > > > resources { ''host'': purge => true } > > > Stop thinking custom scripts; start thinking resources. Most Puppet > > configuration consists of specifying which resources you do or don''t > > want present in which circumstances. Most of the rest of it is about > > defining which resources depend on which others (e.g. this running > > application depends on that configuration file). You describe how a > > system should look and Puppet does what is necessary to make it so. > > > -- > > Bruce > > > I object to intellect without discipline. I object to power without > > constructive purpose. -- Spock-- 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.
trey85stang
2011-Jan-10 16:11 UTC
[Puppet Users] Re: pushing files with host based variables?
Upon further reading, it looks like what I want would be better accomplished with using stored configs? On Jan 10, 9:56 am, trey85stang <trey85st...@gmail.com> wrote:> Thanks for the reply, > > It looks like I would need an entry for every host if I were to take > that route? My environment would require 6000*3 entries... That > doesn''t seem logical. > > Am I understanding this correctly? > > On Jan 10, 4:35 am, Bruce Richardson <itsbr...@workshy.org> wrote: > > > On Sun, Jan 09, 2011 at 10:42:19AM -0800, trey85stang wrote: > > > > 192.168.1.20 host1.domain.com > > > 192.168.1.30 host2.domain.com > > > 192.168.1.250 unique_host.domain.com > > > > Is there a way to manage this with puppet? What I would like to do is > > > be able to check that those 3 entries exist... if not replace the file > > > and generate the custom content that needs to be in the file? > > > If you use host resources, as already recommended, Puppet will create > > the entries if they do not exist. If you only want those entries > > present, tell Puppet to purge all host entries not specified in the > > puppet configuration for that host. > > > host { ''host1.domain.com'': > > ip => ''192.168.1.20'', > > ensure => ''present'' > > } > > > host { ''host2.domain.com'': > > ip => ''192.168.1.30'', > > ensure => ''present'' > > } > > > host { ''unique_host.domain.com'': > > ip => ''192.168.1.250'', > > ensure => ''present'' > > } > > > resources { ''host'': purge => true } > > > Stop thinking custom scripts; start thinking resources. Most Puppet > > configuration consists of specifying which resources you do or don''t > > want present in which circumstances. Most of the rest of it is about > > defining which resources depend on which others (e.g. this running > > application depends on that configuration file). You describe how a > > system should look and Puppet does what is necessary to make it so. > > > -- > > Bruce > > > I object to intellect without discipline. I object to power without > > constructive purpose. -- Spock-- 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.
Bruce Richardson
2011-Jan-10 16:21 UTC
Re: [Puppet Users] Re: pushing files with host based variables?
On Mon, Jan 10, 2011 at 07:56:49AM -0800, trey85stang wrote:> Thanks for the reply, > > It looks like I would need an entry for every host if I were to take > that route? My environment would require 6000*3 entries... That > doesn''t seem logical. > > Am I understanding this correctly?No, you''re still learning. Here''s how to do it (well, one way to do it): class role::basic_host { host { ''localhost'': ip => ''127.0.0.1'', host_aliases => ''localhost.localdomain'', ensure => ''present'' } host { $fqdn: ip => $primary_ipaddress, host_aliases => $hostname, ensure => ''present'' } host { ''host1.domain.com'': ip => ''192.168.1.20'', ensure => ''present'' } host { ''host2.domain.com'': ip => ''192.168.1.30'', ensure => ''present'' } host { ''unique_host.domain.com'': ip => ''192.168.1.250'', ensure => ''present'' } resources { ''host'': purge => true } } node host1 { $primary_ipaddress = ''192.168.1.1'' include role::basic_host } node host2 { $primary_ipaddress = ''192.168.1.2'' include role::basic_host } node host3 { $primary_ipaddress = ''192.168.1.3'' include role::basic_host include some::other::class } You see? No need to define each host resource separately for each node (nodes are what puppet-configured hosts/computers are called in Puppet). What you do is you use classes to group together a linked set of resources, then you include the appropriate classes in your nodes. Notice that I added a couple of other important entries to the list of host resources (you wouldn''t want to be without those, and the "purge => true" line would otherwise remove them)). Note also that I don''t need to specify the values of $fqdn and $hostname, because these are "facts" which puppet can find out for itself (I do specify $primary_ipaddress in this example, because a host may have more than one address, not all of which will be associated with the primary hostname). Keep asking about anything which doesn''t make sense yet. -- Bruce The ice-caps are melting, tra-la-la-la. All the world is drowning, tra-la-la-la-la. -- Tiny Tim.
Bruce Richardson
2011-Jan-10 16:24 UTC
Re: [Puppet Users] Re: pushing files with host based variables?
On Mon, Jan 10, 2011 at 08:11:02AM -0800, trey85stang wrote:> Upon further reading, it looks like what I want would be better > accomplished with using stored configs?No. That''s for something else. Since you have 6000 nodes in your environment, you probably want to look at External Nodes, which would scale better for you than describing all 6000 nodes in a text file. http://docs.puppetlabs.com/guides/external_nodes.html -- Bruce I object to intellect without discipline. I object to power without constructive purpose. -- Spock -- 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.
trey85stang
2011-Jan-10 19:19 UTC
[Puppet Users] Re: pushing files with host based variables?
Bruce, I think what you are saying is clicking now. Now does puppet allow any variable substitution? class role::basic_host { host { ''localhost'': ip => ''127.0.0.1'', host_aliases => ''localhost.localdomain'', ensure => ''present'' } host { $fqdn: ip => $primary_ipaddress, host_aliases => $hostname, ensure => ''present'' } host { ${fqdn/1/2/}: ip => $primary_ip, ensure => ''present'' } } On Jan 10, 10:24 am, Bruce Richardson <itsbr...@workshy.org> wrote:> On Mon, Jan 10, 2011 at 08:11:02AM -0800, trey85stang wrote: > > Upon further reading, it looks like what I want would be better > > accomplished with using stored configs? > > No. That''s for something else. Since you have 6000 nodes in your > environment, you probably want to look at External Nodes, which would > scale better for you than describing all 6000 nodes in a text file. > > http://docs.puppetlabs.com/guides/external_nodes.html > > -- > Bruce > > I object to intellect without discipline. I object to power without > constructive purpose. -- Spock-- 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.
Bruce Richardson
2011-Jan-10 19:46 UTC
Re: [Puppet Users] Re: pushing files with host based variables?
On Mon, Jan 10, 2011 at 11:19:03AM -0800, trey85stang wrote:> Bruce, I think what you are saying is clicking now. > > Now does puppet allow any variable substitution?I do urge you to stop thinking in terms of scripts. It doesn''t map well onto the way that Puppet works. If you mean "How do I apply the same changes to multiple nodes, with different values for each host?", then one answer is to put the common actions into a class and set different variable values in each node declaration. Alternatively, put them into a "define" and pass different parameters each time you call it. You can also use defines to repeate the same actions/changes with multiple values within a single context (e.g. a node). You should be able to find examples in the online documentation. -- Bruce I must admit that the existence of Disneyland (which I know is real) proves that we are not living in Judea in AD 50. -- Philip K. Dick
trey85stang
2011-Jan-10 20:15 UTC
[Puppet Users] Re: pushing files with host based variables?
Sorry for going back to scripts, I keep reading and reading that if you think in terms of scripts you''re only going to confuse yourself been writing automation/admin scripts for way too long. I think you all have giving me a lot more to read up on so I will be doing that. I''ll do some more reading and come back to this when I get a little further. So I will be looking at classes/define/repeat to see what I can come up with. On Jan 10, 1:46 pm, Bruce Richardson <itsbr...@workshy.org> wrote:> On Mon, Jan 10, 2011 at 11:19:03AM -0800, trey85stang wrote: > > Bruce, I think what you are saying is clicking now. > > > Now does puppet allow any variable substitution? > > I do urge you to stop thinking in terms of scripts. It doesn''t map well > onto the way that Puppet works. If you mean "How do I apply the same > changes to multiple nodes, with different values for each host?", then > one answer is to put the common actions into a class and set different > variable values in each node declaration. Alternatively, put them into > a "define" and pass different parameters each time you call it. You can > also use defines to repeate the same actions/changes with multiple > values within a single context (e.g. a node). You should be able to > find examples in the online documentation. > > -- > Bruce > > I must admit that the existence of Disneyland (which I know is real) > proves that we are not living in Judea in AD 50. -- Philip K. Dick > > signature.asc > < 1KViewDownload-- 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.
trey85stang
2011-Jan-10 20:16 UTC
[Puppet Users] Re: pushing files with host based variables?
Forgot to mention I appreciate everyone''s help! -- 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.