DevOps - Puppet类没有选择YAML变量值

时间:2018-04-26 09:44:01

标签: yaml puppet devops hiera

我在创建的Puppet模块上遇到了问题。此模块不检索包含在我的YAML文件中的变量值。

问题似乎来自于它在任何情况下都没有读取params.pp文件......

它们位于正确的目录中,与变量名称中的内容相匹配。

愿你有任何想法吗?

我的班级

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
  }

}

我的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 {
}

我的ConfigTemplates.pp:

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

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

谢谢!

2 个答案:

答案 0 :(得分:2)

  

问题似乎来自于它在任何情况下都没有读取params.pp文件......

这似乎不太可能。类bluesky::components::webapp::offerimport继承自类bluesky::components::webapp::offerimport::params,因此Puppet将确保后者在前者之前进行评估。自史前的Puppet以来,这一直是完全可靠的。

然而,你似乎有不正确的期望。主类继承params类是没用的,因为params类没有声明资源(我也没有间接地假设),而 主类不使用任何变量 即可。主类声明了几个与params类的参数具有相同名称的参数,但这些参数是单独的变量,并且因为它们是主类的本地变量,所以它们在父类范围中隐藏类似命名的变量。

在传统的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数据,直接将值绑定到(仅)目标类。

答案 1 :(得分:0)

这个Params.pp(bluesky :: components :: webapp :: offerimport :: params)类的文件结构如何?

应该是这样的:

bluesky/
├── components
│   └── webapp
│       └── offerimport
│           └── manifests
│               └── params.pp
└── resources
    └── webapps
        └── manifests
            └── params.pp