傀儡参数化类

Joe*_*uts 2 puppet

我无法在 puppet 2.6.4(客户端和主)中使用参数化类

######## from /etc/puppet/manifests/nodes.pp 
# defining one node to use certain version
#######################################################
node 'dev-internal-000008.domain.com' {
         include software($version="dev-2011.02.11")
}
Run Code Online (Sandbox Code Playgroud) # 来自 /etc/puppet/modules/software/manifests/init.pp

我将这里的版本设置为“默认”

#
class software($version="dev-2011.02.04b") {
  File {
    links => follow
  }

  file { "/opt/software_AIR":
    ensure => directory
  }

  file { "/opt/software_AIR/share":
    source => "puppet://puppet/software/air/$version",
    recurse => "true",
  }
}
Run Code Online (Sandbox Code Playgroud) #

傀儡师的错误

#
err: Could not parse for environment production: Syntax error at '='; expected ')' at /etc/puppet/manifests/nodes.pp:10 on node dev-internal-domain.com
Run Code Online (Sandbox Code Playgroud) #

找到了解决方法

尝试

node 'dev-internal-000008.domain.com' {
  class { customsoftware:version => "dev-2011.02.04b" }
}
Run Code Online (Sandbox Code Playgroud)

小智 7

include不幸的是,参数化类不适用于。您必须使用与参数化类同时引入的新替代类声明语法

node 'dev-internal-000008.domain.com' {
    # include software($version="dev-2011.02.11") # (doesn't work)
    class {'software':
        version => "dev-2011.02.11",
    } # works
}
Run Code Online (Sandbox Code Playgroud)

事物:

  • 请注意,它看起来像一个资源(fileservice,等)的声明。
  • 定义和声明都以 class 开头的事实令人困惑,但要小心,你会没事的。
  • 您不能以这种方式多次声明一个类,就像使用include. 这预计会在 2.7 中改变,并且可能会引入一些更友好的语法。