如何使用 Salt Stack 执行多个命令? [英] How can I execute multiple commands using Salt Stack?

查看:45
本文介绍了如何使用 Salt Stack 执行多个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试添加:

 mypack:
   pkg:
     - installed
     - pkgs:
       - mercurial
       - git
   cmd.run:
       - name: 'mkdir -p /opt/mypack'
   cmd.run: 'hg pull -u -R /opt/mypack || hg clone -R /opt https://...'
   cmd.run: 'ln -s /opt/mypack/etc/init.d/xxx /etc/init.d/xxx'

但由于某种原因,状态似乎是执行/安装,但命令没有执行,或者至少不是全部.

But for some reason this the state seems to execute/install but the commands are not executed, or at least not all of them.

我需要一个解决方案来运行多个命令并在其中任何一个失败时使部署失败.

I need a solution to run multiple commands and to fail the deployment if any of these fails.

我知道我可以编写一个 bash 脚本并包含这个 bash 脚本,但我一直在寻找一种仅适用于 YAML 文件的解决方案.

I know that I could write a bash script and include this bash script, but I was looking for a solution that would work with only the YAML file.

推荐答案

你想要这个:

cmd-test:
  cmd.run:
    - name: |
        mkdir /tmp/foo
        chown dan /tmp/foo
        chgrp www-data /tmp/foo
        chmod 2751 /tmp/foo
        touch /tmp/foo/bar

或者这个,我更喜欢,脚本是从主下载的:

Or this, which I would prefer, where the script is downloaded from the master:

cmd-test:
  cmd.script:
    - source: salt://foo/bar.sh
    - cwd: /where/to/run
    - user: fred

这篇关于如何使用 Salt Stack 执行多个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆