puppet:无法评估:无法从环境生产中检索信息

puppet:无法评估:无法从环境生产中检索信息

我看过类似的帖子这里但这并不能解决

目的是复制代理节点上的 bash 脚本并执行。

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,
  }
}

在 /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

我已确保目录存在于 Puppet 服务器中:

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

错误(puppet 应用 /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

前两个 exec 运行正常(删除 yum 并添加 yum)

答案1

感谢 Tim Stoop(他在评论中指出了这一点)。因此,每当您在某个位置添加文件并添加源时,您都需要将它们放在“files”目录中,更重要的是,文件目录不应该在源中命名。

就像我的来源一样:source => "puppet:///modules/raj/myexpect.sh"所以实际文件需要在/etc/puppet/modules/raj/files

puppet 文档中提到了这一点:https://docs.puppet.com/puppet/4.9/modules_fundamentals.html#files

(直到@Tim Stoop 在上述评论中指出之前,我完全没有注意到这一点。

其次,模块中的路径files不正确。您需要在其中输入包括文件名在内的完整路径。使用ensure => 'present'puppet 可确保文件存在,如果不存在,则会创建该文件。

因此:path =>/tmp/myexpect.sh是正确的。

完整正确的清单如下:

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,
  }
}

相关内容