首页 文章

用于“配置make install”的Saltstack

提问于
浏览
14

我正在用SaltStack弄湿我的脚 . 我已经完成了我的第一个状态(带有静态配置的Vim安装程序),而我正在开发第二个状态 .

不幸的是, there isn't an Ubuntu package for the application I'd like my state to install. I will have to build the application myself. Is there a "best practice" for doing "configure-make-install" type installations with Salt? 或者我应该只使用cmd?

特别是,如果我是手工做的话,我会做一些事情:

wget -c http://example.com/foo-3.4.3.tar.gz
tar xzf foo-3.4.3.tar.gz
cd foo-3.4.3
./configure --prefix=$PREFIX && make && make install

2 回答

  • 23

    我们假设 foo-3.4.3.tar.gz 被检入GitHub . 您可以在状态文件中使用以下方法:

    git:
      pkg.installed
    
    https://github.com/nomen/foo.git:
      git.latest:
        - rev: master
        - target: /tmp/foo
        - user: nomen
        - require:
          - pkg: git
    
    foo_deployed:
      cmd.run:
        - cwd: /tmp/foo
        - user: nomen
        - name: |
            ./configure --prefix=/usr/local
            make
            make install
        - require:
          - git: https://github.com/nomen/foo.git
    

    您的配置 prefix 位置可以作为salt pillar传递 . 如果构建过程更复杂,您可以考虑编写custom state .

  • 10

    如果您愿意,可以使用状态模块来抽象前两行 .

    但是你也可以在目标minion上运行命令 .

    install-foo:
      cmd.run:
        - name: |
            cd /tmp
            wget -c http://example.com/foo-3.4.3.tar.gz
            tar xzf foo-3.4.3.tar.gz
            cd foo-3.4.3
            ./configure --prefix=/usr/local
            make
            make install
        - cwd: /tmp
        - shell: /bin/bash
        - timeout: 300
        - unless: test -x /usr/local/bin/foo
    

    只需确保包含 unless 参数即可使脚本具有幂等性 .

    或者,将bash脚本分发给minion并执行 . 见:How can I execute multiple commands using Salt Stack?

    至于 best practice ?我建议使用 fpm 来创建.deb或.rpm包并安装它 . 至少,将该tarball复制到salt master并且不再依赖外部资源在三年之后存在 .

相关问题