【问题标题】:Missing resources when running "puppet agent --noop"运行“puppet agent --noop”时缺少资源
【发布时间】: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


    【解决方案1】:

    很遗憾,目前没有办法克服这个限制。

    ensure 属性不会因为缺少所有者而失败 - 我相信该文件最终将归 root 所有。这就是为什么当文件不存在时输出更令人愉快的原因。

    关于现有文件的行为:每个资源都是单独考虑的,如果在评估文件时组不存在,则文件资源必须承认失败。没有noop 会(很可能)创建组这一事实不能轻易解释。

    至于你的想法,如果有用户资源,在 noop 条件下忽略这个问题 - 我相信这是有好处的。您会在 Puppet 的Jira 提出功能请求吗?

    更新

    从 Puppet 3.3 开始,您可以使用依赖代理提供的 $clientnoop 值以及 Facter 事实。请注意,定制您的清单以避免在noop 模式下失败有两个后果。

    1. 清单本身变得更难以维护和理解。
    2. 来自noop 运行的报告变得不准确,因为“不安全”属性值不是noop 目录的一部分

    您可以像这样构建清单:

    # this scenario does not actually call for virtual resources at all :-)
    group { $at_group:
      ensure => "present"
    } 
    user { $at_user:
      ensure     => present,
      gid        => "$at_group",
      require    => Group[$at_group],
    } 
    
    file { '/etc/afile':
      mode    => '0440',
      content => template('......erb')
      # require => User[$at_user]  # <- not needed at all, Puppet autorequires the user and group
    }
    
    if ! $::clientnoop {
      File['/etc/afile'] {
        owner   => $at_user,
        group   => $at_group,
      }
    }
    

    ownergroup 属性在 noop 模式下被忽略,其优缺点如上所述。

    综合考虑,我觉得这根本不值得。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      相关资源
      最近更新 更多