SaltStack 常用模块介绍 - cmd


salt-minion:
    - cmd.call
    - cmd.mod_run_check
    - cmd.mod_watch
    - cmd.run
    - cmd.script
    - cmd.wait
    - cmd.wait_call
    - cmd.wait_script
    - cmd.watch
 cmd.run:
        
            Run a command if certain circumstances are met.  Use ``cmd.wait`` if you
            want to use the ``watch`` requisite.
        
            name
                The command to execute, remember that the command will execute with the
                path and permissions of the salt-minion.
        
            onlyif
                A command to run as a check, run the named command only if the command
                passed to the ``onlyif`` option returns true
          仅仅 onlyif 返回 true,才执行。 unless A command to run as a check, only run the named command if the command passed to the ``unless`` option returns false 仅仅 unless 返回 false, 才执行。 cwd The current working directory to execute the command in, defaults to /root user The user name to run the command as group The group context to run the command as shell The shell to use for execution, defaults to the shell grain env A list of environment variables to be set prior to execution. Example: salt://scripts/foo.sh: cmd.script: - env: - BATCH: 'yes' Warning: The above illustrates a common PyYAML pitfall, that **yes**, **no**, **on**, **off**, **true**, and **false** are all loaded as boolean ``True`` and ``False`` values, and must be enclosed in quotes to be used as strings. More info on this (and other) PyYAML idiosyncrasies can be found :doc:`here
</topics/troubleshooting/yaml_idiosyncrasies>`. stateful The command being executed is expected to return data about executing a state umask The umask (in octal) to use when running the command. output_loglevel Control the loglevel at which the output from the command is logged. Note that the command being run will still be logged (loglevel: DEBUG) regardless, unless ``quiet`` is used for this value. quiet The command will be executed quietly, meaning no log entries of the actual command or its return data. This is deprecated as of the **2014.1.0** release, and is being replaced with ``output_loglevel: quiet``. timeout If the command has not terminated after timeout seconds, send the subprocess sigterm, and if sigterm is ignored, follow up with sigkill creates Only run if the file specified by ``creates`` does not exist. New in version 2014.7.0 use_vt Use VT utils (saltstack) to stream the command output more interactively to the console and the logs. This is experimental. Note: cmd.run supports the usage of ``reload_modules``. This functionality allows you to force Salt to reload all modules. You should only use ``reload_modules`` if your cmd.run does some sort of installation (such as ``pip``), if you do not reload the modules future items in your state which rely on the software being installed will fail. getpip: cmd.run: - name: /usr/bin/python /usr/local/sbin/get-pip.py - unless: which pip - require: - pkg: python - file: /usr/local/sbin/get-pip.py - reload_modules: True
ES:
test:
cmd.run:
- name: `which nginx` -s reload
- onlyif: rpm -qa nginx
 cmd.script:
        
            Download a script and execute it with specified arguments.
        
            source
                The location of the script to download. If the file is located on the
                master in the directory named spam, and is called eggs, the source
                string is salt://spam/eggs
        
            template
                If this setting is applied then the named templating engine will be
                used to render the downloaded file. Currently jinja, mako, and wempy
                are supported
        
            name
                Either "cmd arg1 arg2 arg3..." (cmd is not used) or a source
                "salt://...".
        
            onlyif
                Run the named command only if the command passed to the ``onlyif``
                option returns true
        
            unless
                Run the named command only if the command passed to the ``unless``
                option returns false
        
            cwd
                The current working directory to execute the command in, defaults to
                /root
        
            user
                The name of the user to run the command as
        
            group
                The group context to run the command as
        
            shell
                The shell to use for execution. The default is set in grains['shell']
        
            env
                A list of environment variables to be set prior to execution.
                Example:
        
                    salt://scripts/foo.sh:
                      cmd.script:
                        - env:
                          - BATCH: 'yes'
        
                Warning:
        
                    The above illustrates a common PyYAML pitfall, that **yes**,
                    **no**, **on**, **off**, **true**, and **false** are all loaded as
                    boolean ``True`` and ``False`` values, and must be enclosed in
                    quotes to be used as strings. More info on this (and other) PyYAML
                    idiosyncrasies can be found :doc:`here
                    </topics/troubleshooting/yaml_idiosyncrasies>`.
        
            umask
                 The umask (in octal) to use when running the command.
        
            stateful
                The command being executed is expected to return data about executing
                a state
        
            timeout
                If the command has not terminated after timeout seconds, send the
                subprocess sigterm, and if sigterm is ignored, follow up with sigkill
        
            args
                String of command line args to pass to the script.  Only used if no
                args are specified as part of the `name` argument. To pass a string
                containing spaces in YAML, you will need to doubly-quote it:  "arg1
                'arg two' arg3"
        
            creates
                Only run if the file specified by ``creates`` does not exist.
        
                New in version 2014.7.0
        
            use_vt
                Use VT utils (saltstack) to stream the command output more
                interactively to the console and the logs.
                This is experimental.
        
            output_loglevel
                Control the loglevel at which the output from the command is logged.
                Note that the command being run will still be logged (loglevel: DEBUG)
                regardless, unless ``quiet`` is used for this value.

 

转载于:https://www.cnblogs.com/Ning-Saltstack/p/7084617.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值