4

I have seen the similar post here, but that does not solve

Intent is to copy the bash script on agent node and execute.

SLES11SP4-118:~ # cat /etc/puppet/manifests/site.pp
node default {
   include base
}

node 'sles11sp4-170.dev.insiteone.com' {
 class {'base':}
}

class base {
   exec { "remove yum":
   command => 'zypper removerepo 1',
   logoutput => 'true',
   path    => '/usr/bin/'
   }

   exec { "add yum":
   command => 'zypper addrepo -f http://10.156.14.121/repo/RPMS/QA/ QA',
   logoutput => 'true',
   path    => '/usr/bin/'
   }

  file {
    'my_expect_script':
      ensure => 'present',
      source => "puppet:///modules/raj/myexpect.sh",
      path => '/tmp/',
      owner => 'root',
      group => 'root',
      mode  => '0744',
      notify => Exec['run_my_script'],
  }
  exec {
    'run_my_script':
     command => '/tmp/myexpect.sh',
     refreshonly => true,
  }
}

In /etc/puppet.conf

SLES11SP4-118:~ # vim /etc/puppet/puppet.conf
[main]
    dns_alt_names=puppet,puppet.dev.insiteone.com
    server=puppet.dev.insiteone.com
    modulepath=/etc/puppet/modules

I have made sure the directories are present in puppet server :

SLES11SP4-118:~ # puppet config print modulepath
/etc/puppet/modules:/usr/share/puppet/modules

SLES11SP4-118:~ # ls /etc/puppet/modules/raj/
myexpect.sh

SLES11SP4-118:~ # ls /usr/share/puppet/modules/raj/
myexpect.sh

Error (puppet apply /etc/puppet/manifests/site.pp --debug):

err: /Stage[main]/Base/File[my_expect_script]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/raj/myexpect.sh at /etc/puppet/manifests/site.pp:31
notice: /Stage[main]/Base/Exec[run_my_script]: Dependency File[my_expect_script] has failures: true
warning: /Stage[main]/Base/Exec[run_my_script]: Skipping because of failed dependencies

The first two execs works fine though (remove yum and add yum)

RajSanpui
  • 183
  • 1
  • 1
  • 9
  • 2
    Not entirely sure, but I think you need to add another directory in /etc/puppet/modules/raj, namely a files directory. Set the myexpect.sh in there and I would expect it to work. – Tim Stoop Apr 12 '17 at 16:30
  • @TimStoop Thanks a ton for the response, that worked great. If you can please add an answer, so that i can accept (would be useful for others too). – RajSanpui Apr 13 '17 at 14:49
  • So, i did 2 things: 1) Added the `files` directory like Tim mentioned `/etc/puppet/modules/raj/files/myexpect.sh` and next is, i changed the `path` in file class to `path => '/tmp/myexpect.sh` because seems like `ensure` expects the path to the full file where it should ensure to be present, if not it creates. – RajSanpui Apr 13 '17 at 14:50
  • I had that up as an answer, but apparently a moderator thought it wasn't worth it, without explanation whatsoever. – Tim Stoop Apr 13 '17 at 19:29

1 Answers1

2

Thanks to Tim Stoop (who pointed it out in comment). So whenever you add a file in some location and add the source, you need to put them inside the "files" directory, and more importantly the files directory should not be named in the sources.

Like my source is: source => "puppet:///modules/raj/myexpect.sh" so the actual file needs to be in /etc/puppet/modules/raj/files

This is mentioned in the puppet doc: https://docs.puppet.com/puppet/4.9/modules_fundamentals.html#files

(I had missed it completely until @Tim Stoop pointed above in the comments.

Next is, the path in the files module was incorrect. You need to put the entire path including the filename there. Using ensure => 'present' the puppet makes sure the file is present there, if not it creates it.

Hence: path => /tmp/myexpect.sh is correct.

The entire correct manifest is below:

SLES11SP4-118:~ # cat /etc/puppet/manifests/site.pp
node default {
   include base
}

node 'sles11sp4-170.dev.insiteone.com' {
 class {'base':}
}

class base {
   exec { "remove yum":
   command => 'zypper removerepo 1',
   logoutput => 'true',
   path    => '/usr/bin/'
   }

   exec { "add yum":
   command => 'zypper addrepo -f http://10.156.14.121/repo/RPMS/QA/ QA',
   logoutput => 'true',
   path    => '/usr/bin/'
   }

  file {
    'my_expect_script':
      ensure => 'present',
      source => "puppet:///modules/raj/myexpect.sh", # Make sure file is in /etc/puppet/modules/raj/files
      path => '/tmp/myexpect.sh',
      owner => 'root',
      group => 'root',
      mode  => '0744',
      notify => Exec['run_my_script'],
  }
  exec {
    'run_my_script':
     command => '/tmp/myexpect.sh',
     refreshonly => true,
  }
}
RajSanpui
  • 183
  • 1
  • 1
  • 9