Ubuntu

用於 docker 鏡像驗證的 Puppet manifest 配置

  • February 28, 2022

我對 devops/ci/cd 很陌生,所以請耐心等待。

目前,我正在為 docker 圖像驗證設置一個 puppet manifest 配置。讓我嘗試佈局它:

我有一個具有以下配置的 puppet master 伺服器:

  • Puppetmaster 版本:5.5.10-4ubuntu3
  • 兩台伺服器都是linux 20.04
  • 全部託管在 AWS 上

/etc/puppet/code/environments/production/manifests/site.pp

node default {
   include 'docker'
   docker::image { 'jorgemauriciodev/ubuntu-dockerfile-dev-v1': }
}

每次在 .pp 中嘗試新的驗證命令時,我都會使用以下命令重新啟動 puppet master 伺服器:sudo systemctl restart puppet-master

我在我的兩台伺服器(代理和主伺服器)上都安裝了一個名為 garethr-docker 的模組。

在從/代理伺服器上,我有這個鏡像 docker 鏡像存在並正在執行:jorgemauriciodev/ubuntu-dockerfile-dev-v1 第一步,我只想檢查我的從屬伺服器中是否存在該鏡像。稍後,我將確定它正在執行或使用 Dockerfile 建構。

在從/代理伺服器上,我執行:sudo puppet agent –test

我收到以下錯誤消息:

錯誤:無法從遠端伺服器檢索目錄:伺服器上的錯誤 500:伺服器錯誤:評估錯誤:評估函式呼叫時出錯,找不到類 ::docker 用於 ip-123-123-123-123.us-east- 2.compute.internal(文件:/etc/puppet/code/environments/production/manifests/site.pp,行:2,列:5)在節點 ip-123-123-123-123.us-east-2 .compute.internal 警告:未在失敗的目錄上使用記憶體錯誤:無法檢索目錄;跳過跑步

有人知道我對 puppet 清單文件有什麼問題嗎?

編輯1:

我做了一些建議的更改。現在,我的文件有一個不同的名稱並更改了內容:/etc/puppet/code/environments/production/manifests/init.pp

include 'docker'
class { 'docker':
 version => 'latest',
}
docker::image { 'jorgemauriciodev/ubuntu-dockerfile-dev-v1': }

仍然返回相同的錯誤消息。

這是完整的消息:

/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Using configured environment 'production'
Info: Retrieving pluginfacts
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Retrieving plugin
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Info: Retrieving locales
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/indirector/request.rb:272: warning: URI.unescape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::docker for ip-172-31-21-116.us-east-2.compute.internal (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 1, column: 1) on node ip-172-31-21-116.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
/usr/lib/ruby/vendor_ruby/puppet/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0
/usr/lib/ruby/vendor_ruby/puppet/util.rb:461: warning: URI.escape is obsolete
/usr/lib/ruby/vendor_ruby/puppet/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0

編輯2:

我使用以下命令在主伺服器和從/代理伺服器上安裝了更多模組:

sudo puppet module install puppetlabs-docker --version 4.1.2

它仍然向我返回一條錯誤消息,但現在似乎它是一個不同的消息。所以,現在可能是一個語法問題。

這是消息的重要部分。

Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Duplicate declaration: Class[Docker] is already declared; cannot redeclare (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 3) (file: /etc/puppet/code/environments/production/manifests/init.pp, line: 3, column: 1) on node ip-123-123-123-123.us-east-2.compute.internal
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

除了這條消息,它仍然向我返回那些警告,但列表要大得多。但是,我認為目前這不是問題。

puppet 中的錯誤 500 意味著編寫錯誤的程式碼,您能否分享整個配置(init.pp),我可以從那裡告訴您。

class { 'docker':
 version => 'latest',
}

docker::image { 'jorgemauriciodev/ubuntu-dockerfile-dev-v1': }

更多資訊可在此處獲得:https ://forge.puppet.com/modules/puppetlabs/docker

引用自:https://serverfault.com/questions/1094913