【问题标题】:Including a definition by variable包括变量定义
【发布时间】:2013-09-09 23:04:23
【问题描述】:

我正在整理一些 puppet 脚本 - 我有一个需要以非常相似的方式部署的服务列表(可能大约 20 个左右)。

  1. 停止现有服务
  2. 从关系中获取包
  3. 解压到目录
  4. 设置配置变量
  5. 启动服务

问题是#4。每个服务的配置略有不同。我想使用 augeas 为每个服务设置配置,为每个服务的配置定义一个定义,然后将该定义加载到主服务定义中似乎是有意义的。

所以,我得到了类似以下的内容:

definition service ($serviceName) {
    //stopping, wget, unzip

    config[downcase($serviceName)] { "${servicename}_config":
        serviceName => $serviceName
    }

    //start
}

然后,我在配置模块的清单文件夹“foo.pp”中有(例如)

definition config::foo {
    //set some stuff
}

由于我确信我已经违反但不知道的各种规则,这不起作用。有没有一种“标准”的方式来做我想做的事情?

【问题讨论】:

    标签: puppet


    【解决方案1】:

    你可以试试下面的代码。您可以将所有这些放在define 类型中,并带有服务名称myserv 的变量。我建议使用templates 来设置配置,而不是augeas...更容易控制。

    exec { "stop_myserv" :
      command => "service stop myserv",
      path => "/path/to/command/service",
      refreshonly => true,
     }
    
    exec { "get_pkg_from_nexus" :
      command => "/command/to/do/the/above && unzip to/dirctory",
      path => "/path/to/command",
      require => Exec["stop_myserv"],
    }
    
    file { "set_configuration" :
      path => "/etc/somewhere/file",
      content => template("modulename/file.erb"),
      mode => "999",
      group => "jiut",
      owner => "muit",
      require => Exec["get_pkg_from_nexus"],
    }
    
    service { "myserv" :
      ensure => running,
      subscribe => File["set_configuration"],
    }
    

    【讨论】:

      猜你喜欢
      • 2013-05-07
      • 2019-07-04
      • 2012-04-20
      • 2015-04-23
      • 2021-09-12
      • 1970-01-01
      • 2013-02-15
      • 2020-01-17
      • 1970-01-01
      相关资源
      最近更新 更多