【发布时间】:2014-06-19 17:48:13
【问题描述】:
我可能误解了“puppet agent --noop”的工作原理:
在类的定义中,我设置了一个文件的存在,并设置了它的用户和组所有权,这就是我取消 "puppet agent --noop" 时所拥有的:
- 如果文件不存在,“
puppet agent --noop”可以正常工作 - 如果文件存在但用户或组不存在,则“
puppet agent --noop”失败 抱怨丢失的用户或组。 - 如果我简单地运行“
puppet agent”(没有“--noop”)它工作正常:不 无论用户、组或文件以前是否存在:它 创建组、用户和/或文件。
第一个问题:我想“--noop”运行不会验证目录是否要求创建缺少的资源。 不是吗?
第二个问题:有没有什么办法可以做任何形式的mocking来避免启动“--noop时资源丢失的问题“?
让我们粘贴一些代码来展示它:
# yes, it should better be virtual resources
group { $at_group:
ensure => "present"
}
user { $at_user:
ensure => present,
gid => "$at_group",
require => Group[$at_group],
}
file { '/etc/afile':
owner => $at_user,
group => $at_group,
mode => '0440',
content => template('......erb')
require => User[$at_user]
}
输出:
# puppet agent --test --noop
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Caching catalog for pagent02
Info: Applying configuration version '1403055383'
Notice: /Stage[main]/Agalindotest::Install/Group[my_group]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Agalindotest::Install/User[my_user]/ensure: current_value absent, should be present (noop)
Error: Could not find user my_user
Error: /Stage[main]/Agalindotest::Install/File[/etc/afile]/owner: change from 1001 to my_user failed: Could not find user my_user
Error: Could not find group my_group
Error: /Stage[main]/Agalindotest::Install/File[/etc/afiles]/group: change from 1001 to my_group failed: Could not find group my_group
让我们看看如果文件不存在它是如何工作的:
那么“puppet agent --test --noop”就像一个魅力:
Notice: /Stage[main]/Agalindotest::Install/Group[my_group]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Agalindotest::Install/User[my_user]/ensure: current_value absent, should be present (noop)
Notice: /Stage[main]/Agalindotest::Install/File[/etc/afile]/ensure: current_value absent, should be file (noop)
非常感谢!!
/ 天使
【问题讨论】:
标签: puppet