Does puppetmaster knows its own configuration parameters?

146 views
Skip to first unread message

Robert Scheer

unread,
Nov 1, 2010, 1:51:08 PM11/1/10
to puppet...@googlegroups.com
Hi,

I have set up a puppetmaster test server where I can test new releases
of puppet before upgrading our puppetmaster production server.
It works, but there is one issue I'd like to solve:

The puppet.conf for all nodes (except the puppetmasters) is managed by
puppet (in modules/puppet/files/puppet.conf) because it needs to contain
the fqdn of our puppetmaster server: puppetmaster.ourdomain.com.
But every time I export our puppet code repository from subversion to
the test server, I have to manually modify the server name in that file
to puppetmaster-test.ourdomain.com. If I don't, then a test-node connecting
to the test server, will receive a puppet.conf with the production server
name, and subsequent puppet runs will connect to that server instead of
my test server.

As a solution I tried templating puppet.conf but cannot figure out what
variable to use to fill in the current puppet server name.

I could solve that by making a custom fact, but besides the huge overhead
of "puppetd --configprint server" running every 30 minutes on every node,
it is just weird for a server to have to ask the client for its own name.

So I'd really like to fix this in puppet code on the masters only.
Is there a way to access the local configuration parameter 'server'
within puppet? Or is there another, better solution I am missing?


Regards,
Robert Scheer

Patrick

unread,
Nov 1, 2010, 4:07:34 PM11/1/10
to puppet...@googlegroups.com
This isn't a very good answer, but the variable "$servername" contains the name of the server the client think's it's connecting to.  That may do what you want.

Felix Frank

unread,
Nov 2, 2010, 5:24:23 AM11/2/10
to puppet...@googlegroups.com
On 11/01/2010 06:51 PM, Robert Scheer wrote:
> ...

> I could solve that by making a custom fact, but besides the huge overhead
> of "puppetd --configprint server" running every 30 minutes on every node,
> it is just weird for a server to have to ask the client for its own name.
>
> So I'd really like to fix this in puppet code on the masters only.
> Is there a way to access the local configuration parameter 'server'
> within puppet? Or is there another, better solution I am missing?

Sounds to me as though you had finally found a use for the generate
function, e.g. $master_host = generate("dnsdomainname -f").

http://docs.puppetlabs.com/references/stable/function.html#generate

;-) Just kidding, it's a useful feature alright. Maybe it will help you.

Regards,
Felix

Alan Barrett

unread,
Nov 2, 2010, 8:03:54 AM11/2/10
to puppet...@googlegroups.com
On Mon, 01 Nov 2010, Robert Scheer wrote:
> Is there a way to access the local configuration parameter 'server'
> within puppet? Or is there another, better solution I am missing?

See issue 2807 <http://projects.puppetlabs.com/issues/2807>.
In puppet-2.6, you can say

$server = $settings::server

In version 0.25, you can say

$server = inline_template("<%= Puppet.settings[:server] %>").

--apb (Alan Barrett)

Robert Scheer

unread,
Nov 2, 2010, 12:09:48 PM11/2/10
to puppet...@googlegroups.com
On Mon, Nov 01, 2010 at 13:07 -0700, Patrick wrote:

> This isn't a very good answer, but the variable "$servername" contains the name of the server the client think's it's connecting to. That may do what you want.

This is a very good answer! Thank you. Where in the documentation did you
find this? It doesn't seem to be a standard fact from facter: it doesn't
show up in $vardir/yaml/facts/*.yaml on the master.

Robert Scheer
XS4ALL Systeembeheer

Robert Scheer

unread,
Nov 2, 2010, 12:12:26 PM11/2/10
to puppet...@googlegroups.com
On Tue, Nov 02, 2010 at 10:24 +0100, Felix Frank wrote:

> Sounds to me as though you had finally found a use for the generate
> function, e.g. $master_host = generate("dnsdomainname -f").
>
> http://docs.puppetlabs.com/references/stable/function.html#generate
>
> ;-) Just kidding, it's a useful feature alright. Maybe it will help you.

Thanks, I now remember seeing that function a long time ago in the puppet
documentation, but couldn't imagine in what situation that would be useful.
This is one :-)

Robert Scheer
XS4ALL Systeembeheer

Patrick

unread,
Nov 2, 2010, 12:21:59 PM11/2/10
to puppet...@googlegroups.com

Actually, I seem to have it backwards. Looks like $servername is the server-side config variable which is why you can't find it. Alan Barrett seems to have a solution for getting the client side config. On the other hand, if your DNS is configured right, $servername should work too.

Robert Scheer

unread,
Nov 3, 2010, 10:32:08 AM11/3/10
to puppet...@googlegroups.com
On Tue, Nov 02, 2010 at 09:21 -0700, Patrick wrote:

> Actually, I seem to have it backwards. Looks like $servername is the server-side config variable which is why you can't find it. Alan Barrett seems to have a solution for getting the client side config. On the other hand, if your DNS is configured right, $servername should work too.

Ah, now I know the variable name, I found out where this information
comes from:
http://projects.puppetlabs.com/projects/puppet/wiki/Frequently_Asked_Questions#Are+there+variables+available+other+than+those+provided+by+Facter?

My bad for not checking the FAQ. I expected to find this kind of
information in the official documentation (docs.puppetlabs.com)
Thanks again!

Robert Scheer
XS4ALL Systeembeheer

Robert Scheer

unread,
Nov 3, 2010, 10:37:06 AM11/3/10
to puppet...@googlegroups.com
On Tue, Nov 02, 2010 at 14:03 +0200, Alan Barrett wrote:

> In version 0.25, you can say
>
> $server = inline_template("<%= Puppet.settings[:server] %>").

Thanks! Puppet.settings[:server] is exactly what I was looking for. I had
tried variations of server, puppet.server and search(), but failed. Do you
know where in the documentation or in the wiki could I have found this?

Robert Scheer
XS4ALL Systeembeheer

Nigel Kersten

unread,
Nov 3, 2010, 11:37:13 AM11/3/10
to puppet...@googlegroups.com

As always, if you find bugs in the documentation, please feel free to
either supply patches or simply report the bugs.

http://projects.puppetlabs.com/projects/puppet-docs
https://github.com/puppetlabs/puppet-docs

>
> Robert Scheer
> XS4ALL Systeembeheer
>
> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
>
>

--
Nigel Kersten - Puppet Labs -  http://www.puppetlabs.com

Alan Barrett

unread,
Nov 3, 2010, 11:56:17 AM11/3/10
to puppet...@googlegroups.com
On Wed, 03 Nov 2010, Robert Scheer wrote:
> > In version 0.25, you can say
> >
> > $server = inline_template("<%= Puppet.settings[:server] %>").
>
> Thanks! Puppet.settings[:server] is exactly what I was looking for. I had
> tried variations of server, puppet.server and search(), but failed. Do you
> know where in the documentation or in the wiki could I have found this?

No, sorry. I think I picked it up from reading the source code.

--apb (Alan Barrett)

Reply all
Reply to author
Forward
0 new messages