http://docs.puppetlabs.com/references/latest/configuration.html#reportdir gives 
a list of certnames. 

I use FQDN for my certname, so ... 


“Sometimes I think the surest sign that intelligent life exists elsewhere in 
the universe is that none of it has tried to contact us.” 
Bill Waterson (Calvin & Hobbes) 

----- Original Message -----
From: "jcbollinger" <john.bollin...@stjude.org> 
To: puppet-users@googlegroups.com 
Sent: Wednesday, September 11, 2013 10:50:59 AM 
Subject: [Puppet Users] Re: getting array of hostnames of clients 




On Wednesday, September 11, 2013 2:49:50 AM UTC-5, Steve Wray wrote: 


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 






In other words, this is intended to retrieve the desired information via the 
master's REST API. I'm not quite making the connection here, however: how is 
putting that expression into a fact supposed to achieve your result? 

Do you mean you have a custom fact that executes that command and parses the 
YAML result to produce the desired array? That seems odd, because in that case 
'localhost' probably would not resolve to the correct machine (it would be the 
client, not the master), and because the result is not a property of the node. 

Or do you mean that you pass the command itself as a literal fact value, which 
the master executes locally to extract the result? Again in that case the value 
is not a property of the node, so it doesn't appear to make much sense to use a 
fact. Also, it would be a serious security risk for the master to execute 
commands provided by clients. 


<blockquote>



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 

</blockquote>



There could be a connection. I have lately seen some evidence that puppetdb may 
not reliably escape fact values when it stores them. That would be a serious 
flaw, but I cannot confirm its existence. 

Alternatively, if you have also updated your master, then it may be that the 
data returned by the REST call has changed in form or content. Do you get what 
you expect if you run it from the command line? 


<blockquote>





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. 
</blockquote>



Yuck. 


<blockquote>




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: 



</blockquote>



Facts are properties of target nodes, and their values are evaluated there. 
Dropping a bunch of files on the master could allow the Puppet agent to collect 
data from them into a fact when it runs on the Puppet master server, but it 
cannot do anything for agents running on other nodes. Do you need the 
information on nodes other than the master? 


<blockquote>




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. 
</blockquote>



If you're not getting the fact at all, even after you restart the agent (though 
that should not be necessary), then I conclude that the fact has not been 
synced to the client. 


<blockquote>




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. 
</blockquote>



On which command line? You could have the fact installed on the master, but not 
synced to clients. 


<blockquote>




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. 


</blockquote>



    1. You are collecting the Files only on the master, therefore only the 
master's $::nodelist fact could provide the information you want. 
    2. Facts are evaluated before catalog compilation, therefore even the 
master's $::nodelist fact would be perpetually one cycle behind. 

<blockquote>





So, sorry, but I have three questions: 


1. why isn't that curl getting the facts? Why is it getting this NoMethod 
error? 
</blockquote>



Beats me. It might help for you to explain more fully how you are using it, and 
to present the curl output actually generated. 


<blockquote>


2. why isn't that new nodelist fact working? If a fact has an error where does 
this get logged? 
</blockquote>



See my discussion above for possibilities. Any log output would show up in the 
agent's log destination, which by default is the regular system log. On the 
agent. 


<blockquote>


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. 


</blockquote>



There is probably an easier way, but it's very unclear what you actually do 
want. You are focusing very narrowly on getting an array of hostnames, but that 
is probably not the best vehicle to get you to your ultimate objective. Quite 
possibly exported resources would do the trick for you if used correctly. I 
have no familiarity with Smokeping, though, so you'll have to help me there. 

Are you building this from scratch, or using a third party module such as 
https://github.com/tobru/puppet-smokeping ? What ultimately needs to appear on 
the target node(s) (presumably contents of some file)? What declarations, 
specifically, do you want to be able to make in your Puppet manifests? 


John 



-- 
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 puppet-users+unsubscr...@googlegroups.com. 
To post to this group, send email to puppet-users@googlegroups.com. 
Visit this group at http://groups.google.com/group/puppet-users . 
For more options, visit https://groups.google.com/groups/opt_out . 

-- 
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 puppet-users+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
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