2014-02-11 124 views
13

我用SaltStack弄湿了自己的脚。我已经完成了我的第一个状态(一个静态配置的Vim安装程序),我正在开发第二个状态。Saltstack for“configure make install”

不幸的是,没有Ubuntu应用程序包,我希望我的状态安装。我将不得不自己构建应用程序。使用Salt进行“configure-make-install”类型安装有没有“最佳实践”?或者我应该只使用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 
+0

也https://github.com/SS-archive/salt-states/blob/master/small/ruby-1.9.2/init.sls – Paolo

回答

21

有状态模块抽象的前两行,如果你想。

但你也可以只运行在目标仆从(S)的命令。

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,并且不要依赖外部资源在三年后出现在那里。

+0

关于外部资源的好处。我可能会在主服务器上设置一个nginx服务器来镜像我需要的资源。感谢您的建议! – nomen

+2

您的除非条款不会按照您的预期工作。它应该是一个纯粹的字符串输入,而不是一个列表。它目前总是返回true。 –

+0

已修复。感谢@TavisRudd –

9

我们假设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

相关问题