%PDF- %PDF-
Direktori : /lib/python2.7/site-packages/salt/pillar/ |
Current File : //lib/python2.7/site-packages/salt/pillar/file_tree.pyc |
� ���^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 Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z e j e � Z d � Z d � Z e d d d e d � Z d e e e d d d e d � Z d � Z d S( uo The ``file_tree`` external pillar allows values from all files in a directory tree to be imported as Pillar data. .. note:: This is an external pillar and is subject to the :ref:`rules and constraints <external-pillars>` governing external pillars. .. versionadded:: 2015.5.0 In this pillar, data is organized by either Minion ID or Nodegroup name. To setup pillar data for a specific Minion, place it in ``<root_dir>/hosts/<minion_id>``. To setup pillar data for an entire Nodegroup, place it in ``<root_dir>/nodegroups/<node_group>`` where ``<node_group>`` is the Nodegroup's name. Example ``file_tree`` Pillar ============================ Master Configuration -------------------- .. code-block:: yaml ext_pillar: - file_tree: root_dir: /srv/ext_pillar follow_dir_links: False keep_newline: True The ``root_dir`` parameter is required and points to the directory where files for each host are stored. The ``follow_dir_links`` parameter is optional and defaults to False. If ``follow_dir_links`` is set to True, this external pillar will follow symbolic links to other directories. .. warning:: Be careful when using ``follow_dir_links``, as a recursive symlink chain will result in unexpected results. .. versionchanged:: 2018.3.0 If ``root_dir`` is a relative path, it will be treated as relative to the :conf_master:`pillar_roots` of the environment specified by :conf_minion:`pillarenv`. If an environment specifies multiple roots, this module will search for files relative to all of them, in order, merging the results. If ``keep_newline`` is set to ``True``, then the pillar values for files ending in newlines will keep that newline. The default behavior is to remove the end-of-file newline. ``keep_newline`` should be turned on if the pillar data is intended to be used to deploy a file using ``contents_pillar`` with a :py:func:`file.managed <salt.states.file.managed>` state. .. versionchanged:: 2015.8.4 The ``raw_data`` parameter has been renamed to ``keep_newline``. In earlier releases, ``raw_data`` must be used. Also, this parameter can now be a list of globs, allowing for more granular control over which pillar values keep their end-of-file newline. The globs match paths relative to the directories named for minion IDs and nodegroups underneath the ``root_dir`` (see the layout examples in the below sections). .. code-block:: yaml ext_pillar: - file_tree: root_dir: /path/to/root/directory keep_newline: - files/testdir/* .. note:: In earlier releases, this documentation incorrectly stated that binary files would not affected by the ``keep_newline`` configuration. However, this module does not actually distinguish between binary and text files. .. versionchanged:: 2017.7.0 Templating/rendering has been added. You can now specify a default render pipeline and a black- and whitelist of (dis)allowed renderers. ``template`` must be set to ``True`` for templating to happen. .. code-block:: yaml ext_pillar: - file_tree: root_dir: /path/to/root/directory render_default: jinja|yaml renderer_blacklist: - gpg renderer_whitelist: - jinja - yaml template: True Assigning Pillar Data to Individual Hosts ----------------------------------------- To configure pillar data for each host, this external pillar will recursively iterate over ``root_dir``/hosts/``id`` (where ``id`` is a minion ID), and compile pillar data with each subdirectory as a dictionary key and each file as a value. For example, the following ``root_dir`` tree: .. code-block:: text ./hosts/ ./hosts/test-host/ ./hosts/test-host/files/ ./hosts/test-host/files/testdir/ ./hosts/test-host/files/testdir/file1.txt ./hosts/test-host/files/testdir/file2.txt ./hosts/test-host/files/another-testdir/ ./hosts/test-host/files/another-testdir/symlink-to-file1.txt will result in the following pillar tree for minion with ID ``test-host``: .. code-block:: text test-host: ---------- apache: ---------- config.d: ---------- 00_important.conf: <important_config important_setting="yes" /> 20_bob_extra.conf: <bob_specific_cfg has_freeze_ray="yes" /> corporate_app: ---------- settings: ---------- common_settings: // This is the main settings file for the corporate // internal web app main_setting: probably bob_settings: role: bob .. note:: The leaf data in the example shown is the contents of the pillar files. i ( t absolute_importt print_functiont unicode_literalsN( t sixc C@ s t j d | j | j � d S( u. Log salt.utils.path.os_walk() error. u %s: %sN( t logt errort filenamet strerror( t err( ( s9 /usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt _on_walk_error� s c C@ s� t | t � r | St j j | | � } x[ | D]S } y t j | | � rO t SWq0 t k r� t j | t j | � � r� t Sq0 Xq0 Wt S( u` Return a boolean stating whether or not a file's trailing newline should be removed. To figure this out, first check if keep_newline is a boolean and if so, return its opposite. Otherwise, iterate over keep_newline and check if any of the patterns match the file path. If a match is found, return False, otherwise return True. ( t isinstancet boolt ost patht joint fnmatcht Falset TypeErrorR t text_typet True( t prefixt file_namet keep_newlinet full_patht pattern( ( s9 /usr/lib/python2.7/site-packages/salt/pillar/file_tree.pyt _check_newline� s c C@ s� i } t j j t t � } t j j | � } x�t j j j | d t d t d | �D]`\ } } } | } t j j | � } t j j | | � } | | k rg } | } x2 | r� t j j | � \ } } | j d | � q� Wx | r� | | j d � } q� Wn x | D] } i | | <qWx�| D]�} t j j | | � } t j j | � sft j d | � q#n d } y� t j j j | d � �r } | j t d � } x'