1

I have been trying to copy and execute a shell script residing in puppet master machine to my puppet agent

This is my code

[root@ip-****** manifests]# cat site.pp
class mymodule::myklass{
  file {'my_bash_script':
      ensure => 'file',
      source => '/etc/puppet/modules/mymodule/my_bash_script.sh',
      path   => '/home/ec2-user/my_bash_script.sh',
      owner  => 'root',
      mode   => '755',
      notify => Exec['run_my_script'],
  }
  exec { 'run_my_script':
    command => '/home/ec2-user/my_bash_script.sh',
  }
}
include mymodule::myklass

my script:

[root@ip-********* mymodule]# cat my_bash_script.sh
#!/bin/sh
mv /usr/bin/node /usr/bin/bnode
ln -s /usr/local/bin/node /usr/bin/node
mv /usr/bin/npm /usr/bin/bnpm
ln -s /usr/local/bin/npm /usr/bin/npm

I am getting the following error:

[root@ip-*********** /]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ip*****************8
Info: Applying configuration version '1472235841'
Error: /Stage[main]/Mymodule::Myklass/File[my_bash_script]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/mymodule/my_bash_script.sh
Notice: /Stage[main]/Mymodule::Myklass/Exec[run_my_script]: Dependency File[my_bash_script] has failures: true
Warning: /Stage[main]/Mymodule::Myklass/Exec[run_my_script]: Skipping because of failed dependencies
Notice: Finished catalog run in 0.08 seconds

Can anyone please help me resolve this error?

1 Answer 1

1

You have to use the puppet module URI to source your file resources if they are located in your module/files directories:

file {'my_bash_script':
  ensure => 'file',
  source => 'puppet:///modules/mymodule/my_bash_script.sh',
  path   => '/home/ec2-user/my_bash_script.sh',
  owner  => 'root',
  mode   => '755',
  notify => Exec['run_my_script'],
}

Note the documentation here: https://docs.puppet.com/puppet/latest/reference/types/file.html#file-attribute-source

If it still fails with that error, then that means the file is missing from your $modulepath/mymodule/files/my_bash_script.sh so you need to place it there.

Furthermore, your bash script could be converted to intrinsic Puppet DSL, and it is odd that you are including a class inside of itself at the end.

Sign up to request clarification or add additional context in comments.

5 Comments

Error: /Stage[main]/Mymodule::Myklass/File[my_bash_script]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/mymodule/my_bash_script.sh
thanks. removing the line 'include mymodule::myklass' resolved the error. but the commands i mentioned in the bash script is not executed in the agent. is there anything i am missing ? please let me know
@Ishwarya Use this docs.puppet.com/puppet/latest/reference/types/… in your exec resource to help debug by seeing what the exec resource output is actually doing.
ok thanks. just fyi i have been trying to copy and execute a shell script residing in puppet master machine to my puppet agent.
@ Matt, there is no log of shell script execution coming on puppet client when I tried using accepted answer. My shell script has only one line "echo hi hello", shouldn't "hi hello" get printed in puppet agent log?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.