�
�Udac @` s� d d l m Z m Z m Z e Z i d d 6d g d 6d d 6Z d Z d 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 m Z d d
l m Z d
d
e d
d � Z d
d � Z d � Z e d k r� e � n d
S( i ( t absolute_importt divisiont print_functions 1.1t metadata_versiont stableinterfacet statust coret supported_bysj
---
module: assemble
short_description: Assemble configuration files from fragments
description:
- Assembles a configuration file from fragments.
- Often a particular program will take a single configuration file and does not support a
C(conf.d) style structure where it is easy to build up the configuration
from multiple sources. C(assemble) will take a directory of files that can be
local or have already been transferred to the system, and concatenate them
together to produce a destination file.
- Files are assembled in string sorting order.
- Puppet calls this idea I(fragments).
version_added: '0.5'
options:
src:
description:
- An already existing directory full of source files.
type: path
required: true
dest:
description:
- A file to create using the concatenation of all of the source files.
type: path
required: true
backup:
description:
- Create a backup file (if C(yes)), including the timestamp information so
you can get the original file back if you somehow clobbered it
incorrectly.
type: bool
default: no
delimiter:
description:
- A delimiter to separate the file contents.
type: str
version_added: '1.4'
remote_src:
description:
- If C(no), it will search for src at originating/master machine.
- If C(yes), it will go to the remote/target machine for the src.
type: bool
default: no
version_added: '1.4'
regexp:
description:
- Assemble files only if C(regex) matches the filename.
- If not set, all files are assembled.
- Every "\" (backslash) must be escaped as "\\" to comply to YAML syntax.
- Uses L(Python regular expressions,http://docs.python.org/2/library/re.html).
type: str
ignore_hidden:
description:
- A boolean that controls if files that start with a '.' will be included or not.
type: bool
default: no
version_added: '2.0'
validate:
description:
- The validation command to run before copying into place.
- The path to the file to validate is passed in via '%s' which must be present as in the sshd example below.
- The command is passed securely so shell features like expansion and pipes won't work.
type: str
version_added: '2.0'
seealso:
- module: copy
- module: template
- module: win_copy
author:
- Stephen Fromm (@sfromm)
extends_documentation_fragment:
- decrypt
- files
s�
- name: Assemble from fragments from a directory
assemble:
src: /etc/someapp/fragments
dest: /etc/someapp/someapp.conf
- name: Inserted provided delimiter in between each fragment
assemble:
src: /etc/someapp/fragments
dest: /etc/someapp/someapp.conf
delimiter: '### START FRAGMENT ###'
- name: Assemble a new "sshd_config" file into place, after passing validation with sshd
assemble:
src: /etc/ssh/conf.d/
dest: /etc/ssh/sshd_config
validate: /usr/sbin/sshd -t -f %s
N( t
AnsibleModule( t bt
indexbytes( t to_nativec C` s� t j d | � \ } } t j | d � } t } t } x\t t j | � � D]E}
| rn | j |
� rn qL n t j j | |
� } t j j
| � sL | r� t j j | � j d � r� qL n t
| d � � } | j � }
Wd QX| r� | j t d � � n | rZ| rZt j | � d } | j | � t | d � d k rW| j t d � � qWqZn | j |
� t } |
j t d � � r�t } qL t } qL W| j � | S(
s/ assemble a file from a directory of fragments t dirt wbt .t rbNs
i i����i
( t tempfilet mkstempt ost fdopent Falset sortedt listdirt searcht patht joint isfilet basenamet
startswitht opent readt writeR t codecst
escape_decodeR
t Truet endswitht close( t src_patht delimitert compiled_regexpt
ignore_hiddent tmpdirt tmpfdt temp_patht tmpt
delimit_met add_newlinet ft fragmentt fragment_fht fragment_content( ( sB /usr/lib/python2.7/site-packages/ansible/modules/files/assemble.pyt assemble_from_fragmentsx s6 4
c C` sr t j j | � rn y t j | � Wqn t t f k
rj } | d k rk d | t | � f g | d <qk qn Xn d S( Ns# Unable to remove temp file (%s): %st warnings( R R t existst removet IOErrort OSErrort NoneR ( R t resultt e( ( sB /usr/lib/python2.7/site-packages/ansible/modules/files/assemble.pyt cleanup� s c C` s� t d t d t d d d t � d t d d � d t d d d t � d t d d
d t � d t d d
d t � d
t d d � d t d d
d t � d t d d � � d t � } t } d } d } | j d } | j d } | j d } | j d } | j d
} d } | j d }
| j j d d � } t d | d | � } t j j | � sg| j
d d | � n t j j | � s�| j
d d | � n | d k r�y t j
| � } Wq�t j k
r�}
| j
d d t |
� | f � q�Xn | rd | k r| j
d d | � n t | | | |
| j � } | j | � } | | d <y | j | � } Wn t k
rtd } n X| | d <t j j | � r�| j | � } n | | k rt| r&| j | | � \ } } } t d | d | d | � | d <| d k r&t | � | j
d d | | f � q&n | rN| d k rN| j | � | d <n | j | | d | j d �t } n t | | � | j | j � } | j | | � | d! <d"