配置Puppet用户Manifest后客户端未生成新用户,请求排查故障
Puppet客户端未生成指定用户的问题排查
环境信息
- 两台Ubuntu 20.04服务器(VirtualBox部署):
- puppetmaster:IP
192.168.100.8 - puppetclient:IP
192.168.100.9
- puppetmaster:IP
- 已完成Puppet安装、客户端证书签名,服务器间可互相ping通
主机配置
Master端/etc/hosts
cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 puppetmaster.example.com puppetmaster 192.168.100.9 puppetclient.example.com puppetclient
Client端/etc/hosts
cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 puppetclient.example.com puppetclient 192.168.100.8 puppetmaster.example.com puppetmaster puppet
Puppet目录结构与配置
目录结构
root@puppetmaster:/etc/puppet# tree . |-- auth.conf |-- code | `-- environments | `-- production | `-- modules | |-- mymodule | | |-- files | | | `-- test.txt | | `-- manifests | | |-- init.pp | | `-- site.pp | `-- user | `-- manifests | |-- init.pp | `-- site.pp |-- hiera.yaml `-- puppet.conf
puppet.conf内容
cat puppet.conf [main] ssldir = /var/lib/puppet/ssl [master] vardir = /var/lib/puppet cadir = /var/lib/puppet/ssl/ca dns_alt_names = puppet
User模块代码
user/manifests/init.pp
cat code/environments/production/modules/user/manifests/init.pp class user { user { 'testuser123': ensure => present, comment => 'bogo user', home => '/home/testuser123', managehome => true } }
错误的节点定义文件user/manifests/site.pp
root@puppetmaster:/etc/puppet# cat code/environments/production/modules/user/manifests/site.pp node 'puppetclient.example.com' { include user }
执行日志
Master端本地应用模块日志
sudo puppet apply /etc/puppet/code/environments/production/modules/user/manifests/init.pp /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 Notice: Compiled catalog for puppetmaster.example.com in environment production in 0.01 seconds /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/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0 Notice: Applied catalog in 0.01 seconds /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:315: warning: deprecated Object#=~ is called on Puppet::Transaction::Report; it always returns nil /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/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0
Client端执行puppet agent --test日志
user@puppetclient:/home$ sudo puppet agent --test [sudo] password for user: /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 Info: Caching catalog for puppetclient.example.com /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/util.rb:461: warning: URI.escape is obsolete Info: Applying configuration version '1694262084' /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/file_system/uniquefile.rb:126: warning: $SAFE will become a normal global variable in Ruby 3.0 Notice: Applied catalog in 0.01 seconds /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
问题原因
- 节点定义位置错误:Puppet Master默认只会加载环境目录下
manifests/site.pp中的节点定义,不会读取模块内部的site.pp文件。你把针对puppetclient.example.com的节点定义放在了user模块的manifests目录下,导致Master编译客户端目录时无法识别该配置。 - 模块结构不符合规范:Puppet模块的manifests目录应仅存放类、定义等可复用的资源,节点定义属于环境级别的全局配置,不应放在模块内部。
解决步骤
- 创建环境级别的manifests目录(如果不存在):
mkdir -p /etc/puppet/code/environments/production/manifests - 将节点定义移动到环境的site.pp中:
mv /etc/puppet/code/environments/production/modules/user/manifests/site.pp /etc/puppet/code/environments/production/manifests/ - 重启Puppet Master服务,确保配置生效:
systemctl restart puppetserver - 在客户端重新执行agent测试:
sudo puppet agent --test
内容的提问来源于stack exchange,提问作者user1666649
相关产品推荐
相关产品推荐

