2

只是提供一些细节 - 在 AWS 上构建,使用 Puppet 处理 DSC,并引导 Puppet 以便它在新配置的节点上配置和安装 Puppet。

我已经使用 Puppet 工作了一段时间,我发现自己想编写一个仅在创建 vm 时执行的模块。

我的特定用例是我想通过 Puppet 自动将防病毒软件(特别是 Trend Micro Deep Security)安装到新配置的节点上。

运行它的脚本只需要下载、运行和几个 TMDS 特定命令来激活自身等。

如果我使用 Puppet,它会在每次运行时执行此操作(下载、尝试安装、尝试激活),这绝对不是我想要的。

但是,我不认为 Puppet“知道”趋势科技,或者如何获取它,或者 URL 等。所以我不能使用类似的东西:

  service { "trend micro":
    ensure => running,
    ensure => present,
  }

做一些研究,看看博客文章,我知道我的代码结构应该是这样的(我知道这是不正确的):

exec {'function_name':
  # the script that downloads/installs/activates etc.
  command => '/path/to/script.sh', 
  onlyif  => systemctl service_trendmicro, 
  # which system should return 0 or 1 for pass/fail - I only want it to exec on 0 ofc.
}

因此,我的问题是:我如何把它放在一起?

4

2 回答 2

3

您可以使用 Puppet 来运行脚本,就像您正在做的那样。然而,如果你在没有 Puppet 的情况下运行脚本,你最终会遇到同样的问题:很难让它们具有幂等性,维护起来很烦人,而且它们不能移植到其他平台。

该公司似乎提供了Chef 食谱Ansible Playbooks来安装代理。这些应该让您大致了解如何处理 Puppet。

通过查看 Ansible 剧本,很容易将其转换为等效的 Puppet 代码:

exec {'download Trend RPM':
  command => '/bin/wget https://app.deepsecurity.trendmicro.com:443/software/agent/RedHat_EL7/x86_64/ O /tmp/agent.rpm --quiet',
  creates => '/tmp/agent.rpm',
}
->
package {'ds_agent':
  ensure   => 'installed',
  provider => 'rpm',
  source => '/tmp/agent.rpm',
}
~>
service {'ds_agent':
  ensure => running,
  enable => true,
}

我刚刚快速检查了一个 CentOS 7 VM,它似乎对我有用:

Notice: Compiled catalog for centos7.vm in environment production in 1.06 seconds
Notice: /Stage[main]/Main/Exec[download Trend RPM]/returns: executed successfully
Notice: /Stage[main]/Main/Package[ds_agent]/ensure: created
Notice: /Stage[main]/Main/Service[ds_agent]/enable: enable changed 'false' to 'true'
Notice: /Stage[main]/Main/Service[ds_agent]: Triggered 'refresh' from 1 events
Notice: Applied catalog in 8.45 seconds

我建议查看现有的 Ansible 剧本并了解如何转换其余的设置步骤:https ://github.com/deep-security/ansible/blob/master/playbook/

于 2016-02-19T15:33:05.447 回答
-1

看看这个模块:https ://github.com/echocat/puppet-redis

它从源代码安装 Redis。因此它会下载、安装、配置和启动服务。从本质上讲,它的功能等同于您正在寻找的功能。

于 2016-02-18T19:59:21.570 回答