%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/states/ |
Current File : //lib/python2.7/site-packages/salt/states/module.pyo |
� ���^c @@ s* d Z d d l m Z m Z m Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z d � Z e j j j e d � Z e e � d d e j �d � � Z d d � Z d � Z d � Z d � Z e j j j e d � Z d S( u_ Execution of Salt modules from within states ============================================ With `module.run` these states allow individual execution module calls to be made via states. To call a single module function use a :mod:`module.run <salt.states.module.run>` state: .. code-block:: yaml mine.send: module.run: - network.interfaces Note that this example is probably unnecessary to use in practice, since the ``mine_functions`` and ``mine_interval`` config parameters can be used to schedule updates for the mine (see :ref:`here <salt-mine>` for more info). It is sometimes desirable to trigger a function call after a state is executed, for this the :mod:`module.wait <salt.states.module.wait>` state can be used: .. code-block:: yaml fetch_out_of_band: module.run: - git.fetch: - cwd: /path/to/my/repo - user: myuser - opts: '--all' Another example: .. code-block:: yaml mine.send: module.run: - network.ip_addrs: - interface: eth0 And more complex example: .. code-block:: yaml eventsviewer: module.run: - task.create_task: - name: events-viewer - user_name: System - action_type: Execute - cmd: 'c:\netops\scripts\events_viewer.bat' - trigger_type: 'Daily' - start_date: '2017-1-20' - start_time: '11:59PM' Please note, this is a new behaviour of `module.run` function. With the previous `module.run` there are several differences: - The need of `name` keyword - The need of `m_` prefix - No way to call more than one function at once For example: .. code-block:: yaml mine.send: module.wait: - name: network.interfaces - watch: - file: /etc/network/interfaces All arguments that the ``module`` state does not consume are passed through to the execution module function being executed: .. code-block:: yaml fetch_out_of_band: module.run: - name: git.fetch - cwd: /path/to/my/repo - user: myuser - opts: '--all' Due to how the state system works, if a module function accepts an argument called, ``name``, then ``m_name`` must be used to specify that argument, to avoid a collision with the ``name`` argument. Here is a list of keywords hidden by the state system, which must be prefixed with ``m_``: * fun * name * names * state * saltenv For example: .. code-block:: yaml disable_nfs: module.run: - name: service.disable - m_name: nfs Note that some modules read all or some of the arguments from a list of keyword arguments. For example: .. code-block:: yaml mine.send: module.run: - func: network.ip_addrs - kwargs: interface: eth0 .. code-block:: yaml cloud.create: module.run: - func: cloud.create - provider: test-provider - m_names: - test-vlad - kwargs: { ssh_username: 'ubuntu', image: 'ami-8d6d9daa', securitygroup: 'default', size: 'c3.large', location: 'ap-northeast-1', delvol_on_destroy: 'True' } Another example that creates a recurring task that runs a batch file on a Windows system: .. code-block:: yaml eventsviewer: module.run: - name: task.create_task - m_name: 'events-viewer' - user_name: System - kwargs: { action_type: 'Execute', cmd: 'c:\netops\scripts\events_viewer.bat', trigger_type: 'Daily', start_date: '2017-1-20', start_time: '11:59PM' } Another option is to use the new version of `module.run`. With which you can call one (or more!) functions at once the following way: .. code-block:: yaml call_something: module.run: - git.fetch: - cwd: /path/to/my/repo - user: myuser - opts: '--all' By default this behaviour is not turned on. In order to do so, please add the following configuration to the minion: .. code-block:: yaml use_superseded: - module.run i ( t absolute_importt print_functiont unicode_literalsN( t six( t range( t zip( t SaltInvocationError( t with_deprecatedc K@ s i | d 6i d 6t d 6d d 6S( u� Run a single module function only if the watch statement calls it ``name`` The module function to execute ``**kwargs`` Pass any arguments needed to execute the function .. note:: Like the :mod:`cmd.run <salt.states.cmd.run>` state, this state will return ``True`` but not actually execute, unless one of the following two things happens: 1. The state has a :ref:`watch requisite <requisites-watch>`, and the state which it is watching changes. 2. Another state has a :ref:`watch_in requisite <requisites-watch-in>` which references this state, and the state wth the ``watch_in`` changes. u nameu changesu resultu u comment( t True( t namet kwargs( ( s6 /usr/lib/python2.7/site-packages/salt/states/module.pyt wait� s u watchu Sodiumt policyc K@ s d | k r | j d � n i t | � d 6i d 6d d 6d d 6} g | j � D] } d | k rQ | ^ qQ } g } g } xW | D]O } | j d � d } | t k r� | j | � q� t d r� | j | � q� q� W| s� | r�d j | r&d j d t | � d k pd d d j | � p d � p)d | rhd j d t | � d k pMd d d j | � pbd � pkd g � j � | d <| p�| | d <n | d d k rt | d <g } g } x%| D]} | j d � d } y� t | d | j d � d | j | � �} t | | d j d i � � s_t | t � r�| j d j | | j d d � � � q�nH | j d j | t | t � r�| j d d � n | � � | | d | <Wq�t t f k r�} | j d j | | � � q�Xq�Wd j | | � | d <t | � | d <n | S( u: Run a single module function or a range of module functions in a batch. Supersedes ``module.run`` function, which requires ``m_`` prefix to function-specific parameters. :param returner: Specify a common returner for the whole batch to send the return data :param kwargs: Pass any arguments needed to execute the function(s) .. code-block:: yaml some_id_of_state: module.run: - network.ip_addrs: - interface: eth0 - cloud.create: - names: - test-isbm-1 - test-isbm-2 - ssh_username: sles - image: sles12sp2 - securitygroup: default - size: 'c3.large' - location: ap-northeast-1 - delvol_on_destroy: True :return: u nameu changesu u commentu resultu .u :i u testu u"