0

我正在整理一些 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
}

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

4

1 回答 1

0

你可以试试下面的代码。您可以将所有这些都放在一个define带有 service name 变量的类型中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-09-10T02:09:34.053 回答