Matt Wallace
2010-Oct-22 15:41 UTC
[Puppet Users] Accessing Facter in other languages than Ruby?
Hi all, We''re writing a few scripts at the moment that could really make use of Facter, however the vast majority of them team (including my self!) are not proficient in Ruby, however they are highly proficient in other languages such as (dare I say it!) Python. Is there (or are there any plans to!) release bindings for other languages to enable facts to be used in scripts other than puppet. Kind regards, Matt -- 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.
Nigel Kersten
2010-Oct-22 15:54 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Fri, Oct 22, 2010 at 8:41 AM, Matt Wallace <lists@truthisfreedom.org.uk>wrote:> Hi all, > > We''re writing a few scripts at the moment that could really make use of > Facter, however the vast majority of them team (including my self!) are not > proficient in Ruby, however they are highly proficient in other languages > such > as (dare I say it!) Python. > > Is there (or are there any plans to!) release bindings for other languages > to > enable facts to be used in scripts other than puppet. >This is on the Facter roadmap, but I don''t have a rough date for you. http://projects.puppetlabs.com/issues/2157 is the bug you should watch if you want to help out or just keep up to date on progress. Feedback in that bug log more than appreciated.> > Kind regards, > > Matt > > -- > 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.
Richard Crowley
2010-Oct-22 15:57 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
> We''re writing a few scripts at the moment that could really make use of > Facter, however the vast majority of them team (including my self!) are not > proficient in Ruby, however they are highly proficient in other languages such > as (dare I say it!) Python.Many of the facts already fork so wiring in the command-line facter tool might not be a bad idea and is certainly possible right now. -- 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.
Darren Chamberlain
2010-Oct-22 16:22 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
* Richard Crowley <r at rcrowley.org> [2010/10/22 08:57]:> > We''re writing a few scripts at the moment that could really make > > use of Facter, however the vast majority of them team (including > > my self!) are not proficient in Ruby, however they are highly > > proficient in other languages such as (dare I say it!) Python. > > Many of the facts already fork so wiring in the command-line > facter tool might not be a bad idea and is certainly possible > right now.I was thinking that, too: import os facts = {} for fact in os.popen("facter").readlines(): n, v = fact.split(" => ") facts[ n ] = v.rstrip() That gives you the facts as a dictionary. -- If not for coffee, I''d have no use for water at all. -- 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.
Matthew Macdonald-Wallace
2010-Oct-24 07:41 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Fri, 2010-10-22 at 08:54 -0700, Nigel Kersten wrote:> > > On Fri, Oct 22, 2010 at 8:41 AM, Matt Wallace > <lists@truthisfreedom.org.uk> wrote: > Hi all, > > We''re writing a few scripts at the moment that could really > make use of > Facter, however the vast majority of them team (including my > self!) are not > proficient in Ruby, however they are highly proficient in > other languages such > as (dare I say it!) Python. > > Is there (or are there any plans to!) release bindings for > other languages to > enable facts to be used in scripts other than puppet. > > > This is on the Facter roadmap, but I don''t have a rough date for you. > > > http://projects.puppetlabs.com/issues/2157 is the bug you should watch > if you want to help out or just keep up to date on progress. > > > Feedback in that bug log more than appreciated.Hi Nigel, I''m not sure I''ve explained myself fully here, so apologies for that. I''m after a way to access the facts in a language other that Ruby, not create them. For example a python script that went something along the lines of: ===================import facter proc1 = facter.facts[''processor_0''] print u''The first processor in this system is %s'' % proc1 ================== That''s a vary basic example, however as I''ve already got a script that creates custom facts from the metadata in our provisioning system, I''m not worried about creating the facts, I just want to be able to access this incredible wealth of information across my various scripts (most of which are/will be in python) regardless of language. I love ruby, and I''m trying to learn it, but the truth is that me and my team don''t really have time to learn another language on top of our day jobs! Thanks in advance, Matt -- 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.
Matthew Macdonald-Wallace
2010-Oct-24 07:42 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Fri, 2010-10-22 at 12:22 -0400, Darren Chamberlain wrote:> * Richard Crowley <r at rcrowley.org> [2010/10/22 08:57]: > > > We''re writing a few scripts at the moment that could really make > > > use of Facter, however the vast majority of them team (including > > > my self!) are not proficient in Ruby, however they are highly > > > proficient in other languages such as (dare I say it!) Python. > > > > Many of the facts already fork so wiring in the command-line > > facter tool might not be a bad idea and is certainly possible > > right now. > > I was thinking that, too: > > import os > > facts = {} > for fact in os.popen("facter").readlines(): > n, v = fact.split(" => ") > facts[ n ] = v.rstrip() > > > That gives you the facts as a dictionary.I was afraid someone would suggest that... ;) :P I''m really looking for bindings that are built into the language (in the same way that I can do a "require ''facter''" for my mcollective agents!) but for Python etc. If all else fails, I guess I could write a wrapper around the above to create a "facts" class, but if it was a native pypi module or egg, that would be ace! I''ll take a look at the sourcecode for Facter and see how easy it would be to translate it into Python. M. Thanks in advance, Matt -- 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.
Yushu Yao
2010-Oct-24 07:44 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
Any reason you can''t use facter the command line? E.g. call in python commands.getstatusoutput("facter") On Oct 24, 2010, at 12:41 AM, Matthew Macdonald-Wallace wrote:> On Fri, 2010-10-22 at 08:54 -0700, Nigel Kersten wrote: >> >> >> On Fri, Oct 22, 2010 at 8:41 AM, Matt Wallace >> <lists@truthisfreedom.org.uk> wrote: >> Hi all, >> >> We''re writing a few scripts at the moment that could really >> make use of >> Facter, however the vast majority of them team (including my >> self!) are not >> proficient in Ruby, however they are highly proficient in >> other languages such >> as (dare I say it!) Python. >> >> Is there (or are there any plans to!) release bindings for >> other languages to >> enable facts to be used in scripts other than puppet. >> >> >> This is on the Facter roadmap, but I don''t have a rough date for you. >> >> >> http://projects.puppetlabs.com/issues/2157 is the bug you should watch >> if you want to help out or just keep up to date on progress. >> >> >> Feedback in that bug log more than appreciated. > > Hi Nigel, > > I''m not sure I''ve explained myself fully here, so apologies for that. > > I''m after a way to access the facts in a language other that Ruby, not > create them. > > For example a python script that went something along the lines of: > > ===================> import facter > > proc1 = facter.facts[''processor_0''] > > print u''The first processor in this system is %s'' % proc1 > ==================> > That''s a vary basic example, however as I''ve already got a script that > creates custom > facts from the metadata in our provisioning system, I''m not worried > about creating the > facts, I just want to be able to access this incredible wealth of > information across my > various scripts (most of which are/will be in python) regardless of > language. > > I love ruby, and I''m trying to learn it, but the truth is that me and my > team don''t > really have time to learn another language on top of our day jobs! > > Thanks in advance, > > Matt > > > > -- > 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.
Matthew Macdonald-Wallace
2010-Oct-24 08:12 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Sun, 2010-10-24 at 00:44 -0700, Yushu Yao wrote:> Any reason you can''t use facter the command line? > E.g. call in python commands.getstatusoutput("facter")Because it''s a dirty hack? ;) We''ve inherited a system where loads of stuff that could be done with shared libraries in various languages (PHP and python mainly) is done using using the appropriate "Shell out to the command line and run this program", that I''m desperately trying to make sure that all our new scripts don''t do this. I realise that the vast majority of libraries are actually "wrappers" around this kind of ''shell out'' process, however it strikes me (and admittedly I''m incredibly paranoid!) that if you''re shelling out to the command line, all it takes is an attacker to send the correct string to the script and they''ve immediately got access to a lot more on the system. Kind regards, Matt -- 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.
Daniel Pittman
2010-Oct-24 12:23 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
Matthew Macdonald-Wallace <lists@truthisfreedom.org.uk> writes:> On Sun, 2010-10-24 at 00:44 -0700, Yushu Yao wrote: > >> Any reason you can''t use facter the command line? >> E.g. call in python commands.getstatusoutput("facter") > > Because it''s a dirty hack? ;)Internally facter does a lot of the same, FWIW. ;) I think what you probably want is ''facter --yaml'', which emits the data in a format easily consumed by other applications. Wrap, or cache, or process that from your Python library and you have a nice, language independent way to get that data. Which is essentially what you want, right? Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- 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.
Nigel Kersten
2010-Oct-24 16:44 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Sun, Oct 24, 2010 at 5:23 AM, Daniel Pittman <daniel@rimspace.net> wrote:> Matthew Macdonald-Wallace <lists@truthisfreedom.org.uk> writes: >> On Sun, 2010-10-24 at 00:44 -0700, Yushu Yao wrote: >> >>> Any reason you can''t use facter the command line? >>> E.g. call in python commands.getstatusoutput("facter") >> >> Because it''s a dirty hack? ;) > > Internally facter does a lot of the same, FWIW. ;)Honestly, the vast majority of Facter facts are just shelling out underneath as Daniel said. I can imagine a magical land where we have native Ruby bindings for everything we currently shell out for, but it''s not here yet... I do like the idea of community maintained wrappers around Facter to at least make coding against Facter in other languages easier, as it really won''t be that much work.> I think what you probably want is ''facter --yaml'', which emits the data in a > format easily consumed by other applications. Wrap, or cache, or process that > from your Python library and you have a nice, language independent way to get > that data. > > Which is essentially what you want, right?I think so. You''ll want to work out how to simulate the ''-p/--puppet'' option, but otherwise it''s all just going to be yaml parsing. I see Matthew''s concerns about security, but I''d argue you simply wouldn''t take input that gets used in actual commands. Facter doesn''t do this, and a wrapper script wouldn''t either. -- 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.
Nigel Kersten
2010-Oct-24 17:36 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
On Sun, Oct 24, 2010 at 9:44 AM, Nigel Kersten <nigel@explanatorygap.net>wrote:> On Sun, Oct 24, 2010 at 5:23 AM, Daniel Pittman <daniel@rimspace.net> > wrote: > > Matthew Macdonald-Wallace <lists@truthisfreedom.org.uk> writes: > >> On Sun, 2010-10-24 at 00:44 -0700, Yushu Yao wrote: > >> > >>> Any reason you can''t use facter the command line? > >>> E.g. call in python commands.getstatusoutput("facter") > >> > >> Because it''s a dirty hack? ;) > > > > Internally facter does a lot of the same, FWIW. ;) > > Honestly, the vast majority of Facter facts are just shelling out > underneath as Daniel said. > > I can imagine a magical land where we have native Ruby bindings for > everything we currently shell out for, but it''s not here yet... > > I do like the idea of community maintained wrappers around Facter to > at least make coding against Facter in other languages easier, as it > really won''t be that much work. >http://projects.puppetlabs.com/issues/5093 filed, please watch if you''re interested, and feel free to start sending patches around. I see this as something the community should be able to contribute and we ship as part of the source tarball. I''m happy to work with anyone on Python support.> > > I think what you probably want is ''facter --yaml'', which emits the data > in a > > format easily consumed by other applications. Wrap, or cache, or process > that > > from your Python library and you have a nice, language independent way to > get > > that data. > > > > Which is essentially what you want, right? > > I think so. You''ll want to work out how to simulate the ''-p/--puppet'' > option, but otherwise it''s all just going to be yaml parsing. > > I see Matthew''s concerns about security, but I''d argue you simply > wouldn''t take input that gets used in actual commands. Facter doesn''t > do this, and a wrapper script wouldn''t either. > > -- > 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.
Daniel Pittman
2010-Oct-25 00:36 UTC
Re: [Puppet Users] Accessing Facter in other languages than Ruby?
Nigel Kersten <nigel@explanatorygap.net> writes:> On Sun, Oct 24, 2010 at 5:23 AM, Daniel Pittman <daniel@rimspace.net> wrote: >> Matthew Macdonald-Wallace <lists@truthisfreedom.org.uk> writes: >>> On Sun, 2010-10-24 at 00:44 -0700, Yushu Yao wrote:[...]>> I think what you probably want is ''facter --yaml'', which emits the data in >> a format easily consumed by other applications. Wrap, or cache, or process >> that from your Python library and you have a nice, language independent way >> to get that data. >> >> Which is essentially what you want, right? > > I think so. You''ll want to work out how to simulate the ''-p/--puppet'' > option, but otherwise it''s all just going to be yaml parsing. > > I see Matthew''s concerns about security, but I''d argue you simply wouldn''t > take input that gets used in actual commands. Facter doesn''t do this, and a > wrapper script wouldn''t either.For my site I would probably deploy this as /etc/cron.d/get-facts: */15 * * * * root /usr/bin/facter --puppet --yaml > /var/tmp/facts.yaml Then you could parse that YAML file as whatever user at whatever time, without having to worry about root access to collect them or whatever. (...or just use mcollective :) Daniel -- ✣ Daniel Pittman ✉ daniel@rimspace.net ☎ +61 401 155 707 ♽ made with 100 percent post-consumer electrons -- 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.
macwall
2010-Oct-25 12:25 UTC
[Puppet Users] Re: Accessing Facter in other languages than Ruby?
On Oct 25, 2:36 am, Daniel Pittman <dan...@rimspace.net> wrote:> > I see Matthew''s concerns about security, but I''d argue you simply wouldn''t > > take input that gets used in actual commands. Facter doesn''t do this, and a > > wrapper script wouldn''t either.That''s a good point and has started me thinking about how I could implement this... :)> For my site I would probably deploy this as /etc/cron.d/get-facts: > */15 * * * * root /usr/bin/facter --puppet --yaml > /var/tmp/facts.yaml > > Then you could parse that YAML file as whatever user at whatever time, without > having to worry about root access to collect them or whatever.Hmmm, I''m currently thinking along the lines of: =-=-=-=-=-=-=-=-=-import os import yaml cmd = "facter --puppet --yaml" facts_dict = yaml.load(cmd) # Do "x" with facts =-=-=-=-=-=-=-=-=-> (...or just use mcollective :)LOL, we''re already using MCollective, this is for a project I''m working on that will (eventually) enable us to interface MCollective with other languages from a client-basis, not just an agent. Cheers, M. -- 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.
R.I.Pienaar
2010-Oct-25 12:29 UTC
Re: [Puppet Users] Re: Accessing Facter in other languages than Ruby?
----- "macwall" <mattmacwall@gmail.com> wrote:> LOL, we''re already using MCollective, this is for a project I''m > working on that will (eventually) enable us to interface MCollective > with other languages from a client-basis, not just an agent.would you mind elaborating on this? Other language support is on my list of things to do, would be good to get peoples wishes captured for when I start down that route -- R.I.Pienaar -- 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.
lists@truthisfreedom.org.uk
2010-Oct-25 14:45 UTC
MCollective Client Languages (WAS Re: [Puppet Users] Re: Accessing Facter in other languages than Ruby?)
Quoting "R.I.Pienaar" <rip@devco.net>:> > ----- "macwall" <mattmacwall@gmail.com> wrote: > >> LOL, we''re already using MCollective, this is for a project I''m >> working on that will (eventually) enable us to interface MCollective >> with other languages from a client-basis, not just an agent. > > would you mind elaborating on this? Other language support is on my list > of things to do, would be good to get peoples wishes captured for when I > start down that routeSure. We have a team of system administrators within our organisation who love the look and power of MCollective but are currently "unable" to utilise it fully as they don''t know ruby (for some reason Python is the language of choice here!). I''m writing a new web interface for our change management system that will be written in DJango, it would be really nice to be able to trigger mcollective actions as part of a change request, but without Python bindings we need to run the SIMPLERPC sinatra client (and we need to make adjustments to it!) so we can use a web interface to send a request to a second API that is running on the same server as the original web interface (more on this at a later date as I''m also planning on releasing it under a BSD-style license). As I''m currently the only SysAd that has even a vague idea about Ruby within my organisation (and my idea of Ruby is very vague as those of you who have seen my code will know!) I''m also the only person who can extend MCollective and write new agents. I''m also therefore the only one who can write new clients for our support teams to use, where as if I could write clients in another language, I could hand out the work across the team - infact, some of our support guys could even write their own tools! Let me know if you would like any more on the above, I''m only to happy to help - Mcollective and puppet are amazing tools and it really is about time I started giving back to the community! ;) Cheers, M. -- 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.
Rob McBroom
2010-Oct-25 15:28 UTC
Re: MCollective Client Languages (WAS Re: [Puppet Users] Re: Accessing Facter in other languages than Ruby?)
On Oct 25, 2010, at 10:45 AM, lists@truthisfreedom.org.uk wrote:> We have a team of system administrators within our organisation who love the > look and power of MCollective but are currently "unable" to utilise it fully > as they don''t know ruby (for some reason Python is the language of choice > here!).Oh, cry me a river. :) We use Python as well (and by “we” I mean “me”), but I would love for one of my co-workers to argue for Ruby if only to demonstrate that they''d heard of it and care about such things. One of the sysadmins I work with prefers to keep track of his servers *in a Word document*. I wish I was kidding. (I put everything in an LDAP database, but he plugs his ears and says “la la la” when that comes up.) -- Rob McBroom <http://www.skurfer.com/> -- 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.