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: TrueES: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.
时间: 2024-10-25 21:46:23

SaltStack 常用模块介绍 - cmd的相关文章

SaltStack 常用模块介绍 - service - pkg - file

salt '*' sys.state_doc service salt-minion: ---------- service: Starting or restarting of services and daemons ============================================== Services are defined as system daemons typically started with system init or rc scripts, ser

SaltStack 常用模块介绍 - sysctl

salt-minion: ---------- sysctl: Configuration of the Linux kernel using sysctl ============================================== Control the kernel sysctl system. vm.swappiness: sysctl.present: - value: 20 sysctl.present: Ensure that the named sysctl va

SaltStack 常用模块介绍 - lvs_server - lvs_service

salt-minion: ---------- lvs_server: Management of LVS (Linux Virtual Server) Real Server ==================================================== lvs_server.present: Ensure that the named service is present. name The LVS server name protocol The service

SaltStack 常用模块介绍 - timezone

salt-minion: ---------- timezone: Management of timezones ======================= The timezone can be managed for the system: America/Denver: timezone.system The system and the hardware clock are not necessarily set to the same time. By default, the

Ansible 自动化运维工具之inventory和常用模块介绍

一.inventory介绍 前面我们介绍过ansible的hosts文件是存放被管理主机的,被管理主机比较少的情况下,直接在hosts中定义即可,但是以后很定会管理多台主机,而ansible可管理的主机集合就叫做inventory.在ansible中,描述你主机的默认方法是将它们列在一个文本文件中,这个文件叫inventory文件. 一个简单的inventory文件可能只包含一组主机名的列表,如下: ftp.testansible.com samba.testansible.com mail.t

python基础31[常用模块介绍]

python基础31[常用模块介绍] python除了关键字(keywords)和内置的类型和函数(builtins),更多的功能是通过libraries(即modules)来提供的. 常用的libraries(modules)如下: 1)python运行时服务 * copy: copy模块提供了对复合(compound)对象(list,tuple,dict,custom class)进行浅拷贝和深拷贝的功能. * pickle: pickle模块被用来序列化python的对象到bytes流,从

Ansible 之 概念和常用模块介绍

1  概述 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署.批量运行命令等功能. ansible是基于模块工作的,本身没有批量部署的能力.真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架.主要包括如下的特性: (1).连接插件connection plugins:负责和被监控端实现通信: (2).host inventory:

Ansible的安装、配置及常用模块介绍

Ansible的安装.配置及常用模块介绍 ansible安装方式 1. ansible安装常用两种方式,yum安装和pip程序安装 这里提供二种安装方式,任选一种即可: 1.使用yum安装 yum install epel-release -y yum install ansible –y 2. 使用pip(python的包管理模块)安装 pip install ansible   #如果没pip,需先安装pip.yum可直接安装: yum install python-pip pip inst

Saltstack系列3:Saltstack常用模块及API

说明 salt '*' sys.list_modules #列出当前版本支持的模块 API原理是通过调用master client模块,实例化一个LocalClient对象,再调用cmd()方法来实现的.以下API实现test.ping的示例:(其他API调用只需要改变cmd即可) import salt.client client = salt.client.LocalClient() ret = client.cmd('*','test.ping) #cmd内格式:'<操作目标>','&l