Custom fact question

59 views
Skip to first unread message

Oliver Beattie

unread,
Jul 29, 2011, 8:55:33 AM7/29/11
to puppet...@googlegroups.com
Hi,

I need to use the output of a script to set the value of a variable. I understand the only way to do this is to use a custom Facter fact.

However, this script will only run when (naturally) it's been installed, which is something Puppet takes care of. Conf files, which I would very much like to be able to install as part of the same run depend on the variable being set.

So, it seems I have myself a lovely little chicken and egg problem — any ideas?

—Oliver

Dominik Zyla

unread,
Jul 29, 2011, 9:16:20 AM7/29/11
to puppet...@googlegroups.com

Hi,

you need this only on puppetmaster and it would be run with a specified
class.

--
Dominik Zyla

Aaron Grewell

unread,
Jul 29, 2011, 9:18:11 AM7/29/11
to puppet...@googlegroups.com

If you put your custom fact in a module and enable plugin sync it should be deployed and run before your manifest IIRC.

> --
> You received this message because you are subscribed to the Google Groups "Puppet Users" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/D9ctUZ0f6CQJ.
> 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.
>

Nan Liu

unread,
Jul 29, 2011, 9:23:53 AM7/29/11
to puppet...@googlegroups.com

You can use pluginsync to load your custom script to the target system
similar to custom facts types/providers. Just place your custom script
in a modules lib directory and it will sync to the agent's plugindest
folder. The only issue at the moment is puppet will try and fail to
load non-ruby files.

notice: /File[/var/opt/lib/pe-puppet/lib/custom/sample.sh]/ensure:
defined content as '{md5}e2e5b99530dc61705e58b8fae70799ac'
info: Loading downloaded plugin /var/opt/lib/pe-puppet/lib/custom/sample.sh
err: Could not load downloaded file
/var/opt/lib/pe-puppet/lib/custom/sample.sh: undefined method `echo'
for main:Object

We have an open ticket http://projects.puppetlabs.com/issues/4135 to
resolve this issue.

Thanks,

Nan

Oliver Beattie

unread,
Jul 29, 2011, 9:25:45 AM7/29/11
to puppet...@googlegroups.com
I need it to run at a specified point during the manifest though. The value of the fact depends on a package being installed. And my config files depend on the value of the fact.

Craig White

unread,
Jul 29, 2011, 11:38:37 AM7/29/11
to puppet...@googlegroups.com

On Jul 29, 2011, at 6:25 AM, Oliver Beattie wrote:

> I need it to run at a specified point during the manifest though. The value of the fact depends on a package being installed. And my config files depend on the value of the fact.

----
Rather than just conceptualize it - assume it works as you want and implement the custom fact (and pluginsync on the clients) and see what happens. If it is still a problem, provide us with the specific problem and someone will be able to give you a specific solution.

Perhaps the hardest thing to grasp about puppet is how to programmatically define subscribe/require/notify so that things happen in a sequence because it is a declarative language.

What I have found that works for me is to have a 'default' node setting that does only configure puppet (puppet.conf & install a sysv script for puppet because I am installing from gems) and force in a specific /etc/apt/sources.list file, add an apt 'key' for an extra debian source, then do an apt-get update/upgrade and stop. At that point, I can define anything else I want for subsequent puppet agent runs and know that the custom 'facts' have been derived and can succeed.

Craig

Paul Morgan

unread,
Jul 29, 2011, 12:17:23 PM7/29/11
to puppet...@googlegroups.com


On Jul 29, 2011 9:25 AM, "Oliver Beattie" <oli...@obeattie.com> wrote:
>
> I need it to run at a specified point during the manifest though. The value of the fact depends on a package being installed. And my config files depend on the value of the fact

Will stages (pre, main, etc) help in this case?

John Martin

unread,
Aug 1, 2011, 6:41:09 AM8/1/11
to Puppet Users
The Fact will get downloaded ahead of the manifest being compiled.
You just need to add a require => Service[myservice] to the config
file.

John

jcbollinger

unread,
Aug 1, 2011, 9:03:45 AM8/1/11
to Puppet Users
If you only need the script for this purpose then instead of writing a
custom fact that reports the output of your script, convert your
script into the custom fact. You have the full power of Ruby at your
disposal. If that's sufficient then it's cleaner in multiple ways.

It sounds like that may not be enough for you, however. If there are
reasons other than script installation why you want the fact value to
be computed somewhere in the middle of the run, then you have two
options that I can see:

1) Accept that (at least) two Puppet runs will sometimes be required
to move a client into its intended state.

2) Move the needed code from your existing script to one of the
affected Package's install scripts. Naturally, this requires rolling
a custom version of that package.


John


jcbollinger

unread,
Aug 1, 2011, 9:10:43 AM8/1/11
to Puppet Users
No. Run stages are a mechanism for establishing resource
relationships, and they do not induce additional fact computations.
No matter how many stages are defined, the facts for a given run are
always determined exactly once, after pluginsync (if that's enabled)
but before everything else.


John
Reply all
Reply to author
Forward
0 new messages