I need to get an array of hostnames of clients of the puppet server.

There doesn't seem to be a simple way to do this so I've tried a few 
methods.

I've tried a curl expression in a fact like this:

curl -s -k -H "Accept: yaml" 
https://localhost:8140/production/facts_search/search?facts.nodetypet=testnodes

where I've got a nodetype fact which works fine for me.

Now, this used to work but doesn't any more. Between it working and now 
I've changed to using puppetdb. I'm not sure if theres a connection.

The error returned is:

Caught NoMethodError: undefined method `<<' for nil:NilClass

The next thing I tried was to get each interesting node to create a file on 
the puppetmaster server. So I now have a bunch of files in /tmp/ with 
distinctive names which contain only the hostname of that puppet client.

I have a fact which is supposed to cat these together and, with luck, turn 
them into an array at some time. What I currently have is this:

require 'facter'
Facter.add("nodelist") do
  setcode do
    path="/tmp"
    if File.exists?(path) && File.directory?(path) && ! Dir[path + 
'/*'].empty?
    output = Facter::Util::Resolution.exec("/bin/cat 
/tmp/testnode*").split('\n').join(',')
    else
      output = "empty"
    end
    output
  end
end

but this isn't getting anything in the fact at all, not even "empty". 
Running that cat command on the commandline returns exactly what I would 
expect.

If I run facter on the commandline like this:
FACTERLIB="/etc/puppet/modules/smokeping_prep/lib/facts" facter  nodelist

I get the list I expect.

On each node I have this:
  @@file { "testnode-{$::fqdn}":
    ensure => file,
    path => "/tmp/testnode-$::fqdn.txt",
    mode => 640, owner => root,
    tag => 'testnodes',
    content => "$::hostname
",
  }

On the puppetmaster node definition I have this:
  File <<| tag == "testnodes" |>>

  file { 'nodelist':
    path => '/tmp/nodelist',
    content => "
$::nodelist
"
    }
}

and I was expecting a file /tmp/nodelist to contain the text from the fact 
$::nodelist but the file is empty.


So, sorry, but I have three questions:

1. why isn't that curl getting the facts? Why is it getting this NoMethod 
error?
2. why isn't that new nodelist fact working? If a fact has an error where 
does this get logged?
3. Is there an easier way to do what I want? An array of hostnames of 
clients matching a fact which I can then pass to other Puppet commands. On 
the face of it I'd think this was something many people would want to do. 
In my case I want to generate a list of Smokeping slaves as a parameter for 
Puppet-generated Smokeping targets. Ie Puppet already generates configs for 
the targets and the slaves and I want to populate the target config with a 
set of slaves.

 facter --version
1.7.2

puppet --version
3.2.4


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to