관리-도구
편집 파일: pull.cpython-39.opt-1.pyc
a �����)g�B����������������������@���s��d�dl�mZmZmZ�eZd�dlmZ�d�dlZd�dl Z d�dl Z d�dlZd�dlZd�dl Z d�dlZd�dlZd�dlZd�dlmZ�d�dlmZ�d�dlmZ�d�dlmZ�d�dlmZmZ�d�d lmZ�d�d lm Z �d�dl!m"Z"�e"��Z#G�dd ��d e�Z$ddd�Z%e&dk�r�e%���dS�)�����)�absolute_import�division�print_function)�CLIN)� constants)�context)�option_helpers)�AnsibleOptionsError)� to_native�to_text)� module_loader)�run_cmd)�Displayc�����������������������s����e�Zd�ZdZdZdZdZdZddd�Zd d iZ dZ edd ���Z��fdd�Z ��fdd�Z��fdd�Zedd���Zedd���Z���ZS�)�PullCLIaO�� Used to pull a remote copy of ansible on each managed node, each set to run via cron and update playbook source via a source repository. This inverts the default *push* architecture of ansible into a *pull* architecture, which has near-limitless scaling potential. None of the CLI tools are designed to run concurrently with themselves, you should use an external scheduler and/or locking to ensure there are no clashing operations. The setup playbook can be tuned to change the cron frequency, logging locations, and parameters to ansible-pull. This is useful both for extreme scale-out as well as periodic remediation. Usage of the 'fetch' module to retrieve logs from ansible-pull runs would be an excellent way to gather and analyze remote logs from ansible-pull. zansible-pull�gitz local.yml)r���� subversion�hg�bzrzFile does not existzFile is not readable)���������playbook.ymla��The name of one the YAML format files to run as an Ansible playbook.This can be a relative path within the checkout. By default, Ansible willlook for a playbook based on the host's fully-qualified domain name,on the host hostname and finally a playbook named *local.yml*.Tc������������������C���sd���d}�t�j�dd�r`t�jd�D�]B}t|t�r>|�dd�|��7�}�qd|v�sRtj�|�r|�d|�7�}�q|�S�)N��Z inventoryFz -i '%s' �,z -i %s ) r����CLIARGS�get� isinstance�list�join�os�path�exists)�inv_opts�inv��r#����4/usr/lib/python3.9/site-packages/ansible/cli/pull.py�_get_inv_cliC���s���� zPullCLI._get_inv_clic��������������������s���t�t|��jddd��t�|�j��t�|�j��t�|�j��t�|�j��t� |�j��t� |�j��t�|�j��|�jjddddd��|�jjd d ddd ��|�jjdddd ddd��|�jjdddddd��|�jjdddd ddd��|�jjddddt� ��d d!��|�jjd"d#d$dd%d��|�jjd&d'dd(d)��|�jjd*d+d,d-d.��|�jjd/d d0dd1d2��|�jjd3d4d5|�jd6|�j|�jf�d��|�jjd7d8d dd9d��|�jjd:d;d dd<d��|�jjd=d>d dd?d��|�jjd@d dAddBd2��|�jjdCtjdDddEd2��dS�)Fz* create an options parser for bin/ansible z0%prog -U <repository> [options] [<playbook.yml>]zDpulls playbooks from a VCS repo and executes them for the local host)�usageZdesc�argszPlaybook(s)r����*)�help�metavar�nargsz--purgeF� store_truez!purge checkout after playbook run)�default�actionr)���z-oz--only-if-changed� ifchangedz8only run the playbook if the repository has been updated)�destr-���r.���r)���z-sz--sleep�sleepNz|sleep for random interval (between 0 and n number of seconds) before starting. This is a useful way to disperse git requests)r0���r-���r)���z-fz--force�forcez<run the playbook even if the repository could not be updatedz-dz--directoryr0���zDpath to the directory to which Ansible will checkout the repository.)r0���r-����typer)���z-Uz--url�urlzURL of the playbook repositoryz--full� fullclonez*Do a full clone, instead of a shallow one.)r0���r.���r)���z-Cz --checkout�checkoutzIbranch/tag/commit to checkout. Defaults to behavior of repository module.)r0���r)���z--accept-host-key�accept_host_keyz6adds the hostkey for the repo url if not already added)r-���r0���r.���r)���z-mz --module-name�module_namezdRepository module name, which ansible will use to check out the repo. Choices are %s. Default is %s.z--verify-commit�verifyz�verify GPG signature of checked out commit, if it fails abort running the playbook. This needs the corresponding VCS module to support such an operationz--clean�cleanz:modified files in the working repository will be discardedz--track-subs� tracksubsztsubmodules will track the latest changes. This is equivalent to specifying the --remote flag to git submodule updatez--check�checkzRdon't make any changes; instead, try to predict some of the changes that may occurz--diff�diffzhwhen changing (small) files and templates, show the differences in those files; works great with --check)�superr����init_parser�opt_helpZadd_connect_options�parserZadd_vault_optionsZadd_runtask_optionsZadd_subset_optionsZadd_inventory_optionsZadd_module_optionsZadd_runas_prompt_options�add_argumentZunfrack_path�DEFAULT_REPO_TYPE�REPO_CHOICES�CZDIFF_ALWAYS)�self�� __class__r#���r$���r?���O���sj���� ������� �������zPullCLI.init_parserc��������������������s����t�t|���|�}|js2t���}tj�t j d|�|_tj�|j�r\tj�|j�s\t d|j���|jr�zt�dt|j��}||_W�n �ty����t d|j���Y�n0�|js�t d��|j|�jvr�t d|jd�|�j�f���|jt_|��|��|S�)NZpullz*%s is not a valid or accessible directory.r���z%s is not a number.z1URL for repository not specified, use -h for helpz*Unsupported repo module %s, choices are %sr���)r>���r����post_process_argsr0����socket�getfqdnr���r���r���rE���ZANSIBLE_HOMEr ����isdirr ���r1����randomZrandint�int� ValueErrorr4���r8���rD���� verbosity�displayZvalidate_conflicts)rF����options�hostnameZsecsrG���r#���r$���rI�������s&���� zPullCLI.post_process_argsc�������������� ������s��t�t|������tj���}t�|�d���t�d�tj ���t ���}t� ��}d�t|||�d�d�|�d�d�g��}|r�d|�}nd}d}tjd �dkr�|d d�dd ��tdtjd ��D����7�}|����}|s�d}|dt�dtj���7�}tjd�dk�r�dtjd�tjd�f�}tjd��r.|dtjd��7�}tjd��rB|d7�}tjd��r`|dtjd��7�}tjd��rt|d7�}tjd��r�|d7�}tjd ��s�|d!7�}�n tjd�d"k�r�d#tjd�tjd�f�}tjd��r�|d$tjd��7�}tjd ��s�|d%7�}n�tjd�d&k�rDd#tjd�tjd�f�}tjd��r�|d$tjd��7�}nftjd�d'k�r�dtjd�tjd�f�}tjd��r�|dtjd��7�}ntd(tjd�d�|�j�f���tjd)��r�|d*7�}t�tjd��} | d+u��r�td,tjd����tj�tj�tj d���} d-| ||tjd�||f�}tjd.�D�]}|d/t�|��7�}�q(tjd0��rrt�d1tjd0����t� tjd0���t�!d2��t�"d3|���t#|d4d5�\} }}| dk�r�tjd6��r�t�$d7��n| S�n$tjd8��r�d9|v�r�t�d:��dS�|��%tjd��}|d+u��r td;��d<| ||f�}tjd=��rBtjd=�D�]}|d>|�7�}�q.tjd?��rltjd?�D�]}|d@|�7�}�qXtjd.�D�]}|d/t�|��7�}�qvtjdA��r�|dB7�}tjdC��r�|dDt&d�tjdC����7�}tjdE��r�|dFt&d�tjdE����7�}tjdG��r|dHtjdG��7�}n|dH|�7�}tjdI��r4|dJ7�}tjdK��rH|dL7�}t�'tjd���|����}|�rn||7�}t�!dM��t�!d3|���t#|d4d5�\} }}tjdN��rt�'dO��z(t�!dPtjd����t(�)tjd���W�nB�t*�y�}�z(t�+dQtjd�t,|�f���W�Y�d+}~n d+}~0�0�| S�)Rz! use Runner lib to do SSH things zStarting Ansible Pull at %F %T� r����.r���zlocalhost,%s,127.0.0.1zlocalhost,127.0.0.1z -c local rP���z -%sr���c�����������������S���s���g�|�]}d��qS�)�vr#���)�.0�xr#���r#���r$���� <listcomp>���������zPullCLI.run.<locals>.<listcomp>z -i localhost, z-e %s zansible_python_interpreter=%sr8���r���zname=%s dest=%sr4���r0���r6���z version=%sr7���z accept_hostkey=yesZprivate_key_filez key_file=%sr9���z verify_commit=yesr;���z track_submodules=yesr5���z depth=1r���zrepo=%s dest=%sz revision=%sz export=yesr���r���z5Unsupported (%s) SCM module for pull, choices are: %sr:���z force=yesNzmodule '%s' not found. z*%s/ansible %s %s -m %s -a "%s" all -l "%s"Z extra_varsz -e %sr1���zSleeping for %d seconds...z0running ansible with VCS module to checkout repozEXEC: %sT)Zliver2���zFUnable to update repository. Continuing with (forced) run of playbook.r/���s���"changed": truez%Repository has not changed, quitting.z!Could not find a playbook to run.z%s/ansible-playbook %s %sZvault_password_filesz --vault-password-file=%sZ vault_idsz --vault-id=%sZbecome_ask_passz --ask-become-passZ skip_tagsz --skip-tags "%s"�tagsz -t "%s"Zsubsetz -l "%s"r<���z -Cr=���z -Dz*running ansible-playbook to do actual work�purge�/zremoving: %szFailed to remove %s: %s)-r>���r����run�datetime�nowrQ����strftimer����sys�argv�platform�noderJ���rK����set�splitr���r����ranger%����shlex�quote� executabler ���rD���r���Zfind_pluginr���r����dirname�abspath�timer1����debugZvvvvr ����warning�select_playbookr ����chdir�shutil�rmtree� Exception�errorr���)rF���r`���re����hostZ hostnamesZ limit_optsZ base_optsr!���Z repo_optsr���Zbin_path�cmdZev�rcZb_outZb_err�playbookZvault_password_fileZvault_id�erG���r#���r$���r^�������s����� * ( �� � 2zPullCLI.runc�����������������C���s&���t�j�|��sdS�t��|�t�j�s"dS�dS�)Nr���r���r���)r���r���r ����access�R_OK)r���r#���r#���r$����try_playbook=��s ����zPullCLI.try_playbookc�����������������C���sp��d�}g�}t�jd�r�t�jd�d�d�ur�g�}t�jd�D�]H}tj�|�|�}t�|�}|dkrp|�d|tj|�f���q2|�|��q2dt |�k�r�t �d�|���n t |�t t�jd��kr�d�|�}|S�t� ��}tj�|�|d��}tj�|�|�d�d�d��} tj�|�tj�} || | fD�]>}t�|�}|dk�r2|}��qNn|�d|tj|�f����q|d�u��rht �d�|���|S�d�S�)Nr'���r���z%s: %s� rT���z.ymlrU���)r���r���r���r���r���r���r~����append�PLAYBOOK_ERRORS�lenrQ���rp���rJ���rK���rg����DEFAULT_PLAYBOOK)r���rz����errorsZ playbooksZbookZ book_pathry���ZfqdnZhostpbZshorthostpbZlocalpbZpbr#���r#���r$���rq���E��s:���� zPullCLI.select_playbook)�__name__� __module__�__qualname__�__doc__�namerC���r����rD���r����Z ARGUMENTSZSKIP_INVENTORY_DEFAULTS�staticmethodr%���r?���rI���r^���r~���rq���� __classcell__r#���r#���rG���r$���r���$���s(���� 4� r���c�����������������C���s���t��|���d�S�)N)r���Zcli_executor)r'���r#���r#���r$����mainh��s����r�����__main__)N)'Z __future__r���r���r���r3���Z __metaclass__Zansible.clir���r_���r���rd���rM���ri���rs���rJ���rb���rn���Zansibler���rE���r���Zansible.cli.argumentsr���r@���Zansible.errorsr ���Zansible.module_utils._textr ���r���Zansible.plugins.loaderr���Zansible.utils.cmd_functionsr ���Zansible.utils.displayr���rQ���r���r����r����r#���r#���r#���r$����<module>���s4�����F