![下载先决条件文件后,如何执行 cmd.script?](https://linux22.com/image/614952/%E4%B8%8B%E8%BD%BD%E5%85%88%E5%86%B3%E6%9D%A1%E4%BB%B6%E6%96%87%E4%BB%B6%E5%90%8E%EF%BC%8C%E5%A6%82%E4%BD%95%E6%89%A7%E8%A1%8C%20cmd.script%EF%BC%9F.png)
我有一个非常简单的用例正在尝试运行:
我需要从主服务器下载并安装一些 tar.gz 源包,然后运行脚本来编译并安装它们所有。
我意识到这可能是一个基本问题,但任何指点都将不胜感激。
/usr/local/src/source1.tar.gz:
file.managed:
- source: salt://sources/source1.tar.gz
- user: root
- group: root
- mode: 644
/usr/local/src/source2.tar.gz:
file.managed:
- source: salt://sources/source2.tar.gz
- user: root
- group: root
- mode: 644
/usr/local/src/source3.tar.gz:
file.managed:
- source: salt://sources/source3.tar.gz
- user: root
- group: root
- mode: 644
//I need something like this, but am not sure how to do it
compile_and_install:
- require: /usr/local/src/source1.tar.gz
- require: /usr/local/src/source2.tar.gz
- require: /usr/local/src/source3.tar.gz
cmd.script:
- source: salt://scripts/compile_and_install.sh
- user: root
- group: root
- shell: /bin/bash
答案1
想通了,以防将来对某人有帮助:
/usr/local/src/source1.tar.gz:
file.managed:
- source: salt://sources/source1.tar.gz
- user: root
- group: root
- mode: 644
/usr/local/src/source2.tar.gz:
file.managed:
- source: salt://sources/source2.tar.gz
- user: root
- group: root
- mode: 644
/usr/local/src/source3.tar.gz:
file.managed:
- source: salt://sources/source3.tar.gz
- user: root
- group: root
- mode: 644
compile_and_install:
cmd.script:
- require:
- file: /usr/local/src/source1.tar.gz
- file: /usr/local/src/source2.tar.gz
- file: /usr/local/src/source3.tar.gz
- source: salt://scripts/compile_and_install.sh
- user: root
- group: root
- shell: /bin/bash
答案2
最近版本的 salt 默认开启了“状态自动排序”,从而消除了大部分这种麻烦。 http://docs.saltstack.com/ref/states/ordering.html#state-auto-ordering
也就是说,您的解决方案是明确说明要求的更好的解决方案。