Ask Your Question
0

How to use a puppet file in exec

asked 2013-06-25 15:45:34 -0500

doc75 gravatar image

Hello,

I would like to launch a command inside an exec that would receive as its argument a file included in the module (like puppet:///modules/maodulename/filename).

Is there anyway to do that ? Thanks

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-06-25 16:31:28 -0500

updated 2013-06-25 16:37:32 -0500

The file will be the parameter for the exec or the content of the file will be ?

File as parameter

If it's the former it's trivial :

$my_file_arg = '/tmp/myarg.txt'

file { $my_file_arg:
  content => "Hello now",
}

exec {"Use $my_file_arg":
  require => File[$my_file_arg],
  command => "/bin/sed -i s/Hello/Bye/g $my_file_arg",
}

Then :

$ Notice: /Stage[main]//File[/tmp/myarg.txt]/content: content changed '{md5}eae30b7e92a3f86a14b73bcbf2e012f4' to '{md5}9047c28dc2e1d336f291fa13b35e1068'
Notice: /Stage[main]//Exec[Use /tmp/myarg.txt]/returns: executed successfully 
Notice: Finished catalog run in 0.10 seconds
$ cat /tmp/myarg.txt
Bye now

Content of the file as parameter

If ... (more)

edit flag offensive delete link more

Comments

Thanks for your answer. Actually I used the first way. But I wanted something slightly different. I have a zip file on the master (under files directory) and wanted to ...(more)

doc75 gravatar imagedoc75 ( 2013-06-26 12:35:40 -0500 )edit
2

answered 2013-06-25 16:35:05 -0500

Ancillas gravatar image

Sure. First, make sure the file is created on disk using a File resource.

file {'config-file':
  ensure => present,
  path   => '/tmp/config-file',
  owner  => 'root',
  group  => 'root',
  mode   => '0644',
  source => 'puppet:///modules/yourmodule/config-file',
}

Now call your Exec, making sure that the Exec requires the File resource so that it runs only after the file has been created.

Exec {'your-command':
  command => '/path/to/your/command --file /tmp/config-file',
}

# Ensures that the file is created before running the command
File['config-file'] -> Exec['your-command']
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

Stats

Asked: 2013-06-25 15:45:34 -0500

Seen: 18,888 times

Last updated: Jun 25 '13