HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //proc/self/root/lib/python3.9/site-packages/ansible/modules/__pycache__/assemble.cpython-39.pyc
a

�)g#�@s�ddlmZmZmZeZdZdZdZddl	Z	ddl
Z
ddlZddlZddl
mZddlmZmZddlmZdd
d�Zddd
�Zdd�Zedkr�e�dS)�)�absolute_import�division�print_functiona\
---
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(true)), 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(false), it will search for src at originating/master machine.
    - If C(true), it will go to the remote/target machine for the src.
    type: bool
    default: yes
    version_added: '1.4'
  regexp:
    description:
    - Assemble files only if C(regex) matches the filename.
    - If not set, all files are assembled.
    - Every C(\) (backslash) must be escaped as C(\\) to comply to YAML syntax.
    - Uses L(Python regular expressions,https://docs.python.org/3/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'
attributes:
    action:
      support: full
    async:
      support: none
    bypass_host_loop:
      support: none
    check_mode:
      support: none
    diff_mode:
      support: full
    platform:
      platforms: posix
    safe_file_operations:
      support: full
    vault:
      support: full
      version_added: '2.2'
seealso:
- module: ansible.builtin.copy
- module: ansible.builtin.template
- module: ansible.windows.win_copy
author:
- Stephen Fromm (@sfromm)
extends_documentation_fragment:
    - action_common_attributes
    - action_common_attributes.flow
    - action_common_attributes.files
    - decrypt
    - files
a(
- name: Assemble from fragments from a directory
  ansible.builtin.assemble:
    src: /etc/someapp/fragments
    dest: /etc/someapp/someapp.conf

- name: Insert the provided delimiter between fragments
  ansible.builtin.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
  ansible.builtin.assemble:
    src: /etc/ssh/conf.d/
    dest: /etc/ssh/sshd_config
    validate: /usr/sbin/sshd -t -f %s
�#N)�
AnsibleModule)�b�
indexbytes)�	to_nativeFc	Cs.tj|d�\}}t�|d�}d}d}	tt�|��D]�}
|rF|�|
�sFq2tj�||
�}tj�	|�r2|rxtj�
|��d�rxq2t|d��}|�
�}
Wd�n1s�0Y|	r�|�td��|r�|r�t�|�d}|�|�t|d	�d
kr�|�td��|�|
�d}|
�td���rd}	q2d}	q2|��|S)z/ assemble a file from a directory of fragments )�dir�wbF�.�rbN�
r����
T)�tempfileZmkstemp�os�fdopen�sorted�listdir�search�path�join�isfile�basename�
startswith�open�read�writer�codecs�
escape_decoder�endswith�close)Zsrc_path�	delimiter�compiled_regexp�
ignore_hidden�tmpdirZtmpfdZ	temp_path�tmpZ
delimit_meZadd_newline�f�fragmentZfragment_fhZfragment_content�r*�</usr/lib/python3.9/site-packages/ansible/modules/assemble.py�assemble_from_fragments�s6"&

r,c
Csftj�|�rbzt�|�WnFttfy`}z*|durLd|t|�fg|d<WYd}~n
d}~00dS)Nz#Unable to remove temp file (%s): %s�warnings)rr�exists�remove�IOError�OSErrorr	)r�result�er*r*r+�cleanup�sr4cCs�tttddd�tdd�tddd�tddd�tddd�tdd�tddd�tdd�d	�dd
�}d}d}d}|jd}|jd}|jd
}|jd}|jd}d}	|jd}
|j�dd�}t||d�}tj�|�s�|jd|d�tj�|�s�|jd|d�|du�rRzt	�
|�}	Wn@t	j�yP}
z$|jdt|
�|fd�WYd}
~
n
d}
~
00|�rrd|v�rr|jd|d�t
|||	|
|j�}|�|�}||d<z|�|�}Wnt�y�d}Yn0||d<tj�|��r�|�|�}||k�rr|�r:|�||�\}}}t|||d�|d<|dk�r:t|�|jd||fd�|�rX|du�rX|�|�|d<|j|||jd d!�d}t||�|�|j�}|�||�|d"<d#|d$<|jfi|��dS)%NrT)�type�required�str)r5�boolF)r5�default)�srcr#�dest�backupZ
remote_src�regexpr%�validate)Z
argument_specZadd_file_common_argsr:r;r<r#r=r%r>)r:r;zSource (%s) does not exist)�msgzSource (%s) is not a directoryzInvalid Regexp (%s) in "%s"z%szvalidate must contain %%s: %sZchecksumZmd5sum)�rc�stdout�stderrZ
validationrz"failed to validate: rc:%s error:%sZbackup_file�
unsafe_writes)rC�changedZOKr?)r�dict�params�getrrr.Z	fail_json�isdir�re�compile�errorr	r,r&Zsha1Zmd5�
ValueErrorZrun_commandr4Zbackup_localZatomic_moveZload_file_common_argumentsZset_fs_attributes_if_differentZ	exit_json)�modulerDZ	path_hashZ	dest_hashr:r;r<r#r=r$r%r>r2r3rZpathmd5r@�out�errZ	file_argsr*r*r+�main�s|




�
�






.





rP�__main__)NNFN)N)Z
__future__rrrr5Z
__metaclass__Z
DOCUMENTATIONZEXAMPLESZRETURNrrrIrZansible.module_utils.basicrZansible.module_utils.sixrrZansible.module_utils._textr	r,r4rP�__name__r*r*r*r+�<module>s `
.
S