I am new to Puppet..I am trying to install a shell script and exceute it using Puppet. The shell script after running creates another conf file and places in a specific location /usr/local/conf/app.conf. How can I write a puppet code to execute this script and then take the output file and scp it to another server (in my case its the webserver). Can someone please help.
Asked
Active
Viewed 1.1k times
1 Answers
1
Let's assume you have developed a module named webconfig and your puppet config dir is /etc/puppet.
You would need to store your shell script as /etc/puppet/modules/webconfig/files/script.sh
Your puppet code would partially look like this:
file { '/path/to/script.sh':
ensure => present,
source => 'puppet:///modules/webconfig/script.sh',
mode => '0644',
owner => 'root',
group => 'root',
}
->
exec { 'Generate the config':
command => '/path/to/script.sh',
cwd => '/path/to',
user => 'root',
}
->
exec { 'SCP the config':
command => 'scp /usr/local/conf/app.conf user@remote-server:',
cwd => '/path/to',
user => 'root',
}

Ali Ganjei
- 141
- 4
-
Thank you! This helps. So, if a puppet client is running in the remote server and it is registered with the puppet master running on another server, then can this puppet module be directly executed on the remote server eliminating the need to scp? – Mark Feb 18 '16 at 04:34
-
Well, if puppet agent runs on the target webserver, generating the config file somewhere else and SCPing it there won't be the best solution. As you mentioned it's better to eliminate SCP and generate the config on the server itself. Also, instead of a shell script, you normally create the config using an erb template and puppet's rich built-in and extended functions – Ali Ganjei Feb 19 '16 at 10:15