代码之家  ›  专栏  ›  技术社区  ›  R.Sama

如果条件满足,我如何运行傀儡执行官?

  •  2
  • R.Sama  · 技术社区  · 10 年前

    只需给出一些细节——基于AWS构建,使用Puppet来处理DSC,并引导Puppet以便它在新配置的节点上配置和安装Puppet。

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

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

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

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

    然而,我不认为木偶“知道”Trend Micro,或如何获取它,或URL等。因此,我不能使用以下内容:

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

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

    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.
    }
    

    因此,我的问题是:我如何将这一点结合起来?

    2 回复  |  直到 10 年前
        1
  •  3
  •   Peter Souter    10 年前

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

    似乎有 Chef cookbooks 和 Ansible Playbooks 由公司提供以安装代理。这些应该会让你大致了解如何处理木偶。

    从Ansible的剧本来看,很容易将其转化为等效的木偶代码:

    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虚拟机进行了快速检查,它似乎对我有效:

    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/

        2
  •  -1
  •   Kieran    10 年前

    查看此模块: https://github.com/echocat/puppet-redis

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