DevOps-Puppet类不拾取YAML变量值
我对我正在创建的木偶模块有一个问题。此模块未检索包含在我的YAML文件中的变量值 问题似乎来自于它在任何情况下都没有读取params.pp文件 它们位于正确的目录中,与变量名中的内容相匹配 你能知道吗 我的班级:DevOps-Puppet类不拾取YAML变量值,yaml,puppet,devops,hiera,Yaml,Puppet,Devops,Hiera,我对我正在创建的木偶模块有一个问题。此模块未检索包含在我的YAML文件中的变量值 问题似乎来自于它在任何情况下都没有读取params.pp文件 它们位于正确的目录中,与变量名中的内容相匹配 你能知道吗 我的班级: class bluesky::components::webapp::offerimport ( $temp_path = undef, $rejects_path = undef, $logs_path
class bluesky::components::webapp::offerimport (
$temp_path = undef,
$rejects_path = undef,
$logs_path = undef,
$done_path = undef,
$app_name = undef,
$app_version = undef,
$pkg_prefix = undef,
$archiver = undef,
$pkg_repos = undef,
$interface_input_path = undef,
) inherits bluesky::components::webapp::offerimport::params {
$tmp_dir = "D:\\Temp\\${app_name}_${app_version}"
$install_dir = "D:\\BSIC\\${pkg_prefix}${app_version}"
$pkg = "${pkg_repos}\\CoreLibScripts\\${app_name}_${app_version}.zip"
$inner_zip = "$tmp_dir\\${app_name}.zip"
$output_inner_zip = "$tmp_dir\\Cab"
bluesky::resources::extract { "Extract ${app_name}":
pkg => $pkg,
archiver => $archiver,
output => $tmp_dir,
}
-> bluesky::resources::extract { "Extract InnerZIP ${app_name}":
pkg => $inner_zip,
archiver => $archiver,
output => $output_inner_zip,
}
-> bluesky::resources::copydir { "Copy ${app_name}":
source => $output_inner_zip,
target => $install_dir,
}
-> class {'bluesky::components::webapp::offerimport::configtemplates':
install_dir => $install_dir
}
-> file {["D:\Interface","D:\Interface\OfferImport","D:\BSIC_DATA\OfferImport"]:
ensure => directory
}
-> file {["${interface_input_path}",
"${temp_path}",
"${rejects_path}",
"${logs_path}",
"${done_path}",]:
ensure => directory
}
}
hierarchy:
- name: "Per-node data"
path: "nodes/%{trusted.certname}.yaml"
- name: Common
path: common.yaml
- name: OfferImport
path: offerimport.yaml
defaults:
data_hash: yaml_data
datadir: data
My Params.pp:
class bluesky::components::webapp::offerimport::params (
String $interface_input_path = undef,
String $temp_path = undef,
String $rejects_path = undef,
String $logs_path = undef,
String $done_path = undef,
String $output_path = undef,
String $om_servername = undef,
String $om_dbname = undef,
String $om_login = undef,
String $om_pwd = undef,
String $name_cfg_ptnametopitype = undef,
String $name_cfg_pttors = undef,
String $name_cfg_suppponametotype = undef,
String $mn_schema_file = undef,
String $name_pivot_tmp = undef,
String $name_rejects_nopitype = undef,
String $name_rejects_norstype = undef,
String $name_rejects_piwithoutrs = undef,
String $name_rejects_powithoutpi = undef,
String $name_rejects_rswithoutre = undef,
String $name_warning_productoffering = undef,
String $mn_helper_dll = undef,
String $archiver = lookup('bluesky::params::global::archiver'),
String $pkg_repos = lookup('bluesky::params::global::pkg_repos'),
) inherits bluesky::resources::webapp::params {
}
class bluesky::components::webapp::offerimport::configtemplates(
# $title = undef,
$install_dir = undef,
) inherits bluesky::components::webapp::offerimport::params {
file { "${title} Parameters.ini":
ensure => 'file',
path => "${install_dir}\\Config\\Parameters.ini",
content => template('bluesky/offerimport/config/Parameters.ini.erb'),
}
}
My ConfigTemplates.pp:
class bluesky::components::webapp::offerimport::params (
String $interface_input_path = undef,
String $temp_path = undef,
String $rejects_path = undef,
String $logs_path = undef,
String $done_path = undef,
String $output_path = undef,
String $om_servername = undef,
String $om_dbname = undef,
String $om_login = undef,
String $om_pwd = undef,
String $name_cfg_ptnametopitype = undef,
String $name_cfg_pttors = undef,
String $name_cfg_suppponametotype = undef,
String $mn_schema_file = undef,
String $name_pivot_tmp = undef,
String $name_rejects_nopitype = undef,
String $name_rejects_norstype = undef,
String $name_rejects_piwithoutrs = undef,
String $name_rejects_powithoutpi = undef,
String $name_rejects_rswithoutre = undef,
String $name_warning_productoffering = undef,
String $mn_helper_dll = undef,
String $archiver = lookup('bluesky::params::global::archiver'),
String $pkg_repos = lookup('bluesky::params::global::pkg_repos'),
) inherits bluesky::resources::webapp::params {
}
class bluesky::components::webapp::offerimport::configtemplates(
# $title = undef,
$install_dir = undef,
) inherits bluesky::components::webapp::offerimport::params {
file { "${title} Parameters.ini":
ensure => 'file',
path => "${install_dir}\\Config\\Parameters.ini",
content => template('bluesky/offerimport/config/Parameters.ini.erb'),
}
}
我的YAML
bluesky::components::webapp::offerimport::app_name: OfferImport
bluesky::components::webapp::offerimport::pkg_prefix: OfferImport\OfferImport_
bluesky::components::webapp::offerimport::signal_file: BlueSky.BSIC.DA.UI.dll
bluesky::components::webapp::offerimport::configfolder: config
##
bluesky::components::webapp::offerimport::params::interface_input_path: D:\Interface\OfferImport\Input
bluesky::components::webapp::offerimport::params::temp_path: D:\BSIC_DATA\OfferImport\Temp
bluesky::components::webapp::offerimport::params::rejects_path: D:\BSIC_DATA\OfferImport\Rejects
bluesky::components::webapp::offerimport::params::logs_path: D:\BSIC_DATA\OfferImport\Logs
bluesky::components::webapp::offerimport::params::done_path: D:\BSIC_DATA\OfferImport\Done
bluesky::components::webapp::offerimport::params::output_path: D:\BSIC_DATA\OfferImport\Output
bluesky::components::webapp::offerimport::params::om_servername: Servername
bluesky::components::webapp::offerimport::params::om_dbname: DatabaseName
bluesky::components::webapp::offerimport::params::om_login: DatabaseLogin
bluesky::components::webapp::offerimport::params::om_pwd: DatabasePassword
bluesky::components::webapp::offerimport::params::name_cfg_ptnametopitype: PTNameToPIType.csv
bluesky::components::webapp::offerimport::params::name_cfg_pttors: PTtoREandRS.csv
bluesky::components::webapp::offerimport::params::name_cfg_suppponametotype: SuppPONameToType.csv
bluesky::components::webapp::offerimport::params::mn_schema_file: ProductCatalogtoBIver7.6.0.xsd
bluesky::components::webapp::offerimport::params::name_pivot_tmp: OFFER_IMPORT_PIVOT_TMP.csv
bluesky::components::webapp::offerimport::params::name_rejects_nopitype: OFFER_IMPORT_REJECTS_NoPIType.csv
bluesky::components::webapp::offerimport::params::name_rejects_norstype: OFFER_IMPORT_REJECTS_NoRSorREType.csv
bluesky::components::webapp::offerimport::params::name_rejects_piwithoutrs: OFFER_IMPORT_REJECTS_PIWithoutRS.csv
bluesky::components::webapp::offerimport::params::name_rejects_powithoutpi: OFFER_IMPORT_REJECTS_POWithoutPI.csv
bluesky::components::webapp::offerimport::params::name_rejects_rswithoutre: OFFER_IMPORT_REJECTS_RSWithoutRE.csv
bluesky::components::webapp::offerimport::params::name_warning_productoffering OFFER_IMPORT_ProductOffering_Warning.csv
bluesky::components::webapp::offerimport::params::mn_helper_dll: BlueSky.BSIC.Com.MetraNet.dll
我的hiera.yaml:
class bluesky::components::webapp::offerimport (
$temp_path = undef,
$rejects_path = undef,
$logs_path = undef,
$done_path = undef,
$app_name = undef,
$app_version = undef,
$pkg_prefix = undef,
$archiver = undef,
$pkg_repos = undef,
$interface_input_path = undef,
) inherits bluesky::components::webapp::offerimport::params {
$tmp_dir = "D:\\Temp\\${app_name}_${app_version}"
$install_dir = "D:\\BSIC\\${pkg_prefix}${app_version}"
$pkg = "${pkg_repos}\\CoreLibScripts\\${app_name}_${app_version}.zip"
$inner_zip = "$tmp_dir\\${app_name}.zip"
$output_inner_zip = "$tmp_dir\\Cab"
bluesky::resources::extract { "Extract ${app_name}":
pkg => $pkg,
archiver => $archiver,
output => $tmp_dir,
}
-> bluesky::resources::extract { "Extract InnerZIP ${app_name}":
pkg => $inner_zip,
archiver => $archiver,
output => $output_inner_zip,
}
-> bluesky::resources::copydir { "Copy ${app_name}":
source => $output_inner_zip,
target => $install_dir,
}
-> class {'bluesky::components::webapp::offerimport::configtemplates':
install_dir => $install_dir
}
-> file {["D:\Interface","D:\Interface\OfferImport","D:\BSIC_DATA\OfferImport"]:
ensure => directory
}
-> file {["${interface_input_path}",
"${temp_path}",
"${rejects_path}",
"${logs_path}",
"${done_path}",]:
ensure => directory
}
}
hierarchy:
- name: "Per-node data"
path: "nodes/%{trusted.certname}.yaml"
- name: Common
path: common.yaml
- name: OfferImport
path: offerimport.yaml
defaults:
data_hash: yaml_data
datadir: data
谢谢大家! 这个Params.pp(bluesky::components::webapp::offerimport::Params)类的文件结构如何 应该是这样的:
bluesky/
├── components
│ └── webapp
│ └── offerimport
│ └── manifests
│ └── params.pp
└── resources
└── webapps
└── manifests
└── params.pp
这个Params.pp(bluesky::components::webapp::offerimport::Params)类的文件结构如何 应该是这样的:
bluesky/
├── components
│ └── webapp
│ └── offerimport
│ └── manifests
│ └── params.pp
└── resources
└── webapps
└── manifests
└── params.pp
问题似乎来自于它在任何情况下都没有读取params.pp文件
这似乎极不可能。Classbluesky::components::webapp::offerimport
继承自Classbluesky::components::webapp::offerimport::params
,因此Puppet将确保在计算前者之前先计算后者。这是完全可靠的,因为史前木偶
然而,你似乎有不正确的期望。主类从params类继承是没有用的,因为params类没有声明任何资源(我假设也没有间接声明),并且主类不使用其任何变量。primary类声明了几个与params类的参数同名的参数,但这些参数是单独的变量,并且由于它们是primary类的本地变量,因此它们在父类范围中隐藏了同名参数
在传统的params类模式中,使用params类的变量作为主类参数的默认值。实际上,这样做的能力是在这种情况下涉及类继承的唯一原因。例如:
class foo::params {
$default_env = 'GUE'
$default_greeting = 'Hello, Sailor!'
$default_menace = 'grue'
}
class foo::messages (
$env = $foo::params::default_env,
$greeting = $foo::params::default_greeting,
$menace = $foo::params::menace,
) inherits foo::params {
notify { "In the ${env}, we say '${greeting}' Try not to be eaten by a ${menace}.": }
}
然后可以通过各种方式(包括Hiera数据)将替代值绑定到主类的参数
通过数据绑定设置params类数据是不典型的,因为直接将数据绑定到目标类的参数更简单。我可以想象出这样的情景,但你的似乎不是其中之一。我建议完全去掉params类,修改Hiera数据,将值直接绑定到(仅)目标类
问题似乎来自于它在任何情况下都没有读取params.pp文件
这似乎极不可能。Classbluesky::components::webapp::offerimport
继承自Classbluesky::components::webapp::offerimport::params
,因此Puppet将确保在计算前者之前先计算后者。这是完全可靠的,因为史前木偶
然而,你似乎有不正确的期望。主类从params类继承是没有用的,因为params类没有声明任何资源(我假设也没有间接声明),并且主类不使用其任何变量。primary类声明了几个与params类的参数同名的参数,但这些参数是单独的变量,并且由于它们是primary类的本地变量,因此它们在父类范围中隐藏了同名参数
在传统的params类模式中,使用params类的变量作为主类参数的默认值。实际上,这样做的能力是在这种情况下涉及类继承的唯一原因。例如:
class foo::params {
$default_env = 'GUE'
$default_greeting = 'Hello, Sailor!'
$default_menace = 'grue'
}
class foo::messages (
$env = $foo::params::default_env,
$greeting = $foo::params::default_greeting,
$menace = $foo::params::menace,
) inherits foo::params {
notify { "In the ${env}, we say '${greeting}' Try not to be eaten by a ${menace}.": }
}
然后可以通过各种方式(包括Hiera数据)将替代值绑定到主类的参数
通过数据绑定设置params类数据是不典型的,因为直接将数据绑定到目标类的参数更简单。我可以想象出这样的情景,但你的似乎不是其中之一。我建议完全去掉params类,并修改您的Hiera数据,将值直接绑定到(仅)目标类。您不应该将不推荐的
params.pp
模式与替换的Hiera 5模块数据模式一起使用。我不知道它们是否兼容,但是params.pp
充其量只是一个多余的无用文件,最坏的情况下,它会阻止您的数据查找。@MattSchuchard,params类模式和Hiera 5模块数据之间没有固有的不兼容,但将它们组合起来并不是特别有用。如果有人这样做,结果将遵循Puppet的普通作用域和数据绑定规则。您不应该将不推荐的params.pp
模式与替换的Hiera 5模块数据模式一起使用。我不知道它们是否兼容,但是params.pp
充其量只是一个多余的无用文件,最坏的情况下,它会阻止您的数据查找。@MattSchuchard,params类模式和Hiera 5模块数据之间没有固有的不兼容,但将它们组合起来并不是特别有用。如果有人这样做,结果将遵循Puppet的普通范围和数据绑定规则。