Ask Your Question

Is it possible to have custom function to read the contents of file on the agent node?

asked 2016-02-28 02:30:12 -0500

VeekshaVasanth gravatar image

I want to the content of the file on the agent node where the file is collected exported resource.

edit retag flag offensive close merge delete


Hi Veeksha, Can you please explain a little bit more, what your problem is and what you want to achieve?

rajeevsharma gravatar imagerajeevsharma ( 2016-02-29 01:27:33 -0500 )edit

Hi Rajeev, what i wanted to actually do was to populate the database (run liquibase/sql script) on one of the nodes in a cluster of nodes and export file resource and that file resource be collected on the other nodes which would proceed its configuration based on db status. Is there any better way?

VeekshaVasanth gravatar imageVeekshaVasanth ( 2016-03-01 11:31:46 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-03-02 04:46:59 -0500

rajeevsharma gravatar image

Hi Veeksha,

Yes, it's possible using exporter and collector. I tested the same in my own environment, where I have exported the content of a file on node1 and collected the content on node2. Here is the sample code snippet from site.pp:

## ---- Definisng exporter and collector
class exporter {
 @@file { "/tmp/chef_version.config":
        ensure => file,
        source => "/opt/chef/version-manifest.txt"
        #tag => "mysqlconfig"
# exporter node
node "agentnode1" {
 include exporter
# collector node
node "agentnode2" {
 File <<| |>>

Additionally, it will collect all the exported file on agentnode2, to avoid this you can use tag attribute. After collecting the required file on your node you can write additional resources to complete further steps. Good luck.

edit flag offensive delete link more


Hi Rajeev, Thanks for the above code snippet. But is it possible to get the content of the file in a variable on the collector node?

VeekshaVasanth gravatar imageVeekshaVasanth ( 2016-03-02 07:35:44 -0500 )edit

why not? once you get the file and it's content you can manipulate the data. Try looking for file functions in ruby. Hope that will help.

rajeevsharma gravatar imagerajeevsharma ( 2016-03-02 08:27:17 -0500 )edit

am not that familiar with ruby though, but is it really possible to get the content of collected file resource in a variable on the agent side? Any more pointers you can provide would be helpful.

VeekshaVasanth gravatar imageVeekshaVasanth ( 2016-03-02 21:49:18 -0500 )edit

answered 2016-02-29 06:59:55 -0500

DarylW gravatar image

As far as I know, In a master/agent setup, the only way to get the contents of a file on the agent(not managed by puppet) is via a custom fact.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-28 02:30:12 -0500

Seen: 218 times

Last updated: Mar 02 '16