a )g(@sddlmZmZmZeZddlmZddlZddl Z ddl m Z ddl m Z ddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZmZddl m!Z!e!Z"GdddeZ#dddZ$e%dkre$dS))absolute_importdivisionprint_function)CLIN) constants)context)option_helpers) AnsibleError)PlaybookExecutor)to_bytes)Block)add_all_plugin_dirs)AnsibleCollectionConfig)_get_collection_name_from_path_get_collection_playbook_path)DisplaycsHeZdZdZdZfddZfddZfddZed d Z Z S) PlaybookCLIz the tool to run *Ansible playbooks*, which are a configuration and multinode deployment system. See the project home page (https://docs.ansible.com) for more information. zansible-playbookcstt|jdddt|jt|jt|jt|jt |jt |jt |jt |jt |jt|j|jjddddd|jjd d dd d|jjd d ddd|jjddddd|jjdddd|jjddddddS)Nz,%prog [options] playbook.yml [playbook2 ...]zJRuns Ansible playbooks, executing the defined tasks on the targeted hosts.)usageZdescz--syntax-checksyntax store_truez=perform a syntax check on the playbook, but do not execute it)destactionhelpz --list-tasks listtasksz%list all tasks that would be executedz --list-tagslisttagszlist all available tagsz--stepstepz4one-step-at-a-time: confirm each task before runningz--start-at-taskZ start_at_taskz1start the playbook at the task matching this name)rrargsz Playbook(s)playbook+)rmetavarnargs)superr init_parseropt_helpZadd_connect_optionsparserZadd_meta_optionsZadd_runas_optionsZadd_subset_optionsZadd_check_optionsZadd_inventory_optionsZadd_runtask_optionsZadd_vault_optionsZadd_fork_optionsZadd_module_options add_argument)self __class__8/usr/lib/python3.9/site-packages/ansible/cli/playbook.pyr"&s<                zPlaybookCLI.init_parsercs,tt||}|jt_|j|ddd|S)NT)Z runas_optsZ fork_opts)r!rpost_process_args verbositydisplayZvalidate_conflicts)r&optionsr'r)r*r+EszPlaybookCLI.post_process_argsc shtt|d}d}i}g}tjdD]}t|}|durF|d}nJtj|s^t d|tj |st t |j st d|t|}|s(tjtjt|dd}t|||q(|r|t_tjdstjdstjd stjd s|\}}||d }|\} } } t| tjd tjd rL|| | ttjd| | | |d} | } t| tr`| D]}td|dt|dD]\}}|j dur| !|j n"tj"tj|d}| !|zd#|j$}Wnt%yd}Yn0d|d||j&f}t'|j(|dd#7}tjdrt'| )|j$}|d|j$t*|f7}|D]}|d|7}qvt|t'tjd stjdrd}tjdrd}fdd| j+|d}|,D]*}|-|}|.sq||7}qtjd rJt/}|0|dd#|7}t|qq|dS| SdS) Nrz#the playbook: %s could not be foundz-the playbook: %s does not appear to be a fileZsurrogate_or_strict)errorsZ listhostsrrr)Z conn_passZ become_passZsubsetZ flush_cache)Z playbooks inventoryvariable_managerloader passwordsz playbook: %srZplays,z play #%d (%s): %sz TAGS: [%s]z pattern: %s hosts (%d):z %sz tasks: csd}|jD]}t|tr&||7}q |jtjvr:|jr:q |jt j dr t  t |j}||jr|d|7}n|d|j7}|dd|7}q |S)Nr6rz %sz TAGS: [%s] , )block isinstancer rCZ _ACTION_METAZimplicitupdatetagsrCLIARGSlistunionsetsortnameget_namejoin)btaskmsgZtaskcur_tags_process_blockZall_tagsZmytagsr)r*rJs    z'PlaybookCLI.run.._process_block)playz TASK TAGS: [%s] r8r)1r!rrunrr>rospathexistsr isfilestatS_ISFIFOst_moderdirnameabspathr r appendrZplaybook_pathsZ ask_passwordsZ _play_prereqsrZ get_host_list _flush_cacher r:r?r- enumerateZ_included_pathZ set_basedirrealpathrEhosts TypeErrorrCrAr=Z get_hostslenZget_varscompileZfilter_tagged_tasksZ has_tasksr@rB)r&ZsshpassZ becomepassr4Zb_playbook_dirsrresourceZplaybook_collectionZb_playbook_dirr3r1r2ZpbexresultspidxrKZpb_dirZ host_listmsgZ playhostshostrGZall_varsr9rHr'rIr*rLMs                        zPlaybookCLI.runcCs$|D]}|}||qdSN)Z list_hostsrDZ clear_facts)r1r2rchostnamer)r)r*rWs zPlaybookCLI._flush_cache) __name__ __module__ __qualname____doc__rCr"r+rL staticmethodrW __classcell__r)r)r'r*r s   rcCst|dSrd)rZ cli_executor)rr)r)r*mainsrl__main__)N)&Z __future__rrrtypeZ __metaclass__Z ansible.clirrMrQZansiblerr;rZansible.cli.argumentsrr#Zansible.errorsr Z"ansible.executor.playbook_executorr Zansible.module_utils._textr Zansible.playbook.blockr Zansible.plugins.loaderr Zansible.utils.collection_loaderrZ2ansible.utils.collection_loader._collection_finderrrZansible.utils.displayrr-rrlrfr)r)r)r*s*           E