Set variable value

416 views
Skip to first unread message

Darvin Denmian

unread,
Oct 2, 2012, 2:02:45 PM10/2/12
to puppet...@googlegroups.com
Hi,

Is it possible to set the value of a variable from the content of
a text file?

Regards.

David Schmitt

unread,
Oct 3, 2012, 2:14:13 AM10/3/12
to puppet...@googlegroups.com
See the file() function.

D.

jcbollinger

unread,
Oct 3, 2012, 10:18:18 AM10/3/12
to puppet...@googlegroups.com


On Tuesday, October 2, 2012 1:03:23 PM UTC-5, Darvin Denmian wrote:
Hi,

Is it possible to set the value of a variable from the content of
a text file?


If the target file is on the master, then you can load its entire contents into a variable via the file() function that David suggested:

$myvar = file('/path/to/file')

If needed, you can then use other Puppet functions to parse out the value you want.

Alternatively, you can always write a custom function to parse any file format you want.  If the target file is one that you intend to create and maintain for this purpose, however, then I would recommend using Hiera instead.  It's a little more involved to set up (unless you're on Puppet 3, where it's built in), but it's the de facto standard for accessing external data even on Puppet 2.

On the other hand, if your file resides on the node being configured, then what you're looking for is a custom fact.  They are pretty easy to write and distribute: http://docs.puppetlabs.com/guides/custom_facts.html.


John

Darvin Denmian

unread,
Oct 3, 2012, 10:38:42 AM10/3/12
to puppet...@googlegroups.com
Thanks for your reply. I'll try it right now.

Regards.
> --
> 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/-/I6MysO4VpEsJ.
>
> 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.
Reply all
Reply to author
Forward
0 new messages