使用 puppet 确保 vagrant box 已升级

使用 puppet 确保 vagrant box 已升级

我正在使用 puppet 来配置 vagrant box(在本例中为 Ubuntu)。首次启动 vagrant box(vagrant up)后,运行apt-get upgrade将列出几个更新。我想在第一次启动时运行这些升级,但在让 puppet 运行 apt-get upgrade 时遇到了麻烦:

# run apt-get update
exec { "apt-update":
  command => "/usr/bin/apt-get update"
}

# run apt-get upgrade
exec { "apt-upgrade":
  command => "apt-get upgrade -y",
  path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin",
  require => Exec['apt-update'],
}

以下操作失败:

err: /Stage[main]//Exec[apt-upgrade]/returns: change from notrun to 0 failed: apt-get upgrade -y returned 100 instead of one of [0] at /tmp/vagrant-puppet-1/manifests/site.pp:34

**额外的研究:** 一个 Google 群组帖子提出了以下内容,但没有帮助:

Exec { path => [ "/usr/bin", "/usr/sbin", "/bin", "/usr/local/bin" ] }

我也尝试添加一个之前的调用apt-get -f install -y。但都没有成功。

谢谢!

答案1

因此路径设置是正确的,这篇文章帮助我找到了解决这个问题的最后方法:https://ask.puppetlabs.com/question/1563/why-does-exec-fail-when-executing-directly-succeeds/

本质上,dkpg是错误:

notice: /Stage[main]//Exec[apt-upgrade]/returns: dpkg: warning: 'ldconfig' not found in PATH or not executable.
notice: /Stage[main]//Exec[apt-upgrade]/returns: dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
notice: /Stage[main]//Exec[apt-upgrade]/returns: dpkg: error: 2 expected programs not found in PATH or not executable.
notice: /Stage[main]//Exec[apt-upgrade]/returns: Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin.
notice: /Stage[main]//Exec[apt-upgrade]/returns: E: Sub-process /usr/bin/dpkg returned an error code (2)

当我添加/sbin升级路径时,它就起作用了。

exec { 'apt-upgrade':
  command => "/usr/bin/apt-get --quiet --yes --fix-broken upgrade",
  logoutput => "on_failure",
  path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin:/usr/local/sbin:/sbin",
  require => Exec['apt-update'],
}

答案2

将初始 apt-get 更新请求更改为如下所示:

exec { 'apt-get':
    command => "/usr/bin/apt-get update",
    onlyif => "/bin/sh -c '[ ! -f /var/cache/apt/pkgcache.bin ] || /usr/bin/find /etc/apt/* -cnewer /var/cache/apt/pkgcache.bin | /bin/grep . > /dev/null'",
}

然后你可以这样做:

# run apt-get upgrade
exec { 'apt-upgrade':
  command => "/usr/bin/apt-get upgrade -y",
  require => Exec['apt-update'],
}

相关内容