
    Vhq*                        d dl mZ d dlmZ d dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ d dlmZ d dlmZ d dlmZmZ d dlmZ  e       Z G d de      ZddZ e!dk(  r e         yy)    )annotations)CLIN)	constants)context)option_helpers)AnsibleError)PlaybookExecutor)to_bytes)Block)add_all_plugin_dirs)AnsibleCollectionConfig)_get_collection_name_from_path_get_collection_playbook_path)Displayc                  J     e Zd ZdZdZ fdZ fdZ fdZed        Z	 x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. zansible-playbookc                   t         t        |   dd       t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         t        j                  | j
                         | j
                  j                  dddd       | j
                  j                  d	d
dd       | j
                  j                  dddd       | j
                  j                  dddd       | j
                  j                  ddd       | j
                  j                  dddd       y )Nz,%prog [options] playbook.yml [playbook2 ...]zJRuns Ansible playbooks, executing the defined tasks on the targeted hosts.)usagedescz--syntax-checksyntax
store_truez=perform a syntax check on the playbook, but do not execute it)destactionhelpz--list-tasks	listtasksz%list all tasks that would be executedz--list-tagslisttagszlist all available tagsz--stepstepz4one-step-at-a-time: confirm each task before runningz--start-at-taskstart_at_taskz1start the playbook at the task matching this name)r   r   argszPlaybook(s)playbook+)r   metavarnargs)superr   init_parseropt_helpadd_connect_optionsparseradd_meta_optionsadd_runas_optionsadd_subset_optionsadd_check_optionsadd_inventory_optionsadd_runtask_optionsadd_vault_optionsadd_fork_optionsadd_module_optionsadd_argument)self	__class__s    D/home/dcms/DCMS/lib/python3.12/site-packages/ansible/cli/playbook.pyr%   zPlaybookCLI.init_parser%   s    	k4,@] 	- 	_ 	$$T[[1!!$++.""4;;/##DKK0""4;;/&&t{{3$$T[[1""4;;/!!$++.##DKK0 	  !1&e 	! 	g  k,&M 	! 	O  Z&? 	! 	A  |&\ 	! 	^  !2&Y 	! 	[  mZWZ [    c                    t        |j                  xs |j                        }t        t        |   |      }|j                  r|s	ddg|_        |j                  t        _        | j                  |dd       |S )NneverallT)
runas_opts	fork_opts)
booltags	skip_tagsr$   r   post_process_argsr   	verbositydisplayvalidate_conflicts)r3   optionshavetagsr4   s      r5   r?   zPlaybookCLI.post_process_argsD   sq     9(9(9:T<WE  '/#--DDIr6   c           	     
   t         t        |           d }d }i }g }t        j                  d   D ]  }t        |      }||d   }nt        j                  j                  |      st        d|z        t        j                  j                  |      s@t        j                  t        j                  |      j                        st        d|z        t        |      }|rt        j                  j                  t        j                  j!                  t#        |d                  }t%        |       |j'                  |        |r|t(        _        t        j                  d   sQt        j                  d   s>t        j                  d	   s+t        j                  d
   s| j-                         \  }}||d}| j/                         \  }	}
}t1        j2                  |
t        j                  d          t        j                  d   r| j5                  |
|       t7        t        j                  d   |
||	|      }|j                         }t9        |t:              r|D ]  }t<        j=                  d|d   z         t?        |d         D ]`  \  }}|j@                  |	jC                  |j@                         nPt        j                  jE                  t        j                  j                  |d               }|	jC                  |       	 djG                  |jH                        }d|dz   ||jL                  fz  }tO        |jP                        |ddjG                        z  z  }t        j                  d   rPtO        |
jS                  |jH                              }|d|jH                  tU        |      fz  z  }|D ]
  }|d|z  z  } t<        j=                  |       tO               t        j                  d	   st        j                  d   sd}t        j                  d   rd}fd|jW                  |      }|jY                         D ]/  }|j[                  |      }|j]                         s%| |      z  }1 t        j                  d	   rAt;        j_                              }|ja                          |ddjG                  |      z  z  }t<        j=                  |       c  y|S # tJ        $ r d}Y w xY w)Nr      z#the playbook: %s could not be foundz-the playbook: %s does not appear to be a filesurrogate_or_strict)errors	listhostsr   r   r   )	conn_passbecome_passsubsetflush_cache)	playbooks	inventoryvariable_managerloader	passwordsz
playbook: %sr    plays, z
  play #%d (%s): %s   z	TAGS: [%s]z 
    pattern: %s
    hosts (%d):z	
      %sz    tasks:
c                ,   d}| j                   D ]   }t        |t              r| |      z  } |j                  t        j
                  v r|j                  rIj                  |j                         t        j                  d   sxt        j                  t        |j                                    }|j                          |j                  r|d|j!                         z  z  }n|d|j                  z  z  }|ddj#                  |      z  z  } |S )NrU   r   z      %sz	TAGS: [%s]
, )block
isinstancer   r   C_ACTION_METAimplicitupdater=   r   CLIARGSlistunionsetsortnameget_namejoin)btaskmsgtaskcur_tags_process_blockall_tagsmytagss       r5   rk   z'PlaybookCLI.run.<locals>._process_block   s    &(G() Z#-dE#:$+~d/C$CG'+{{ann'D(0$,OODII$>'.{'C37S^8T3U(0+/99,3zDMMO7S,SG,3zDKK7O,OG(/3CdiiPXFY3Y(YZ" $+Nr6   )playz      TASK TAGS: [%s]
rX   r   )1r$   r   runr   r_   r   ospathexistsr   isfilestatS_ISFIFOst_moder   dirnameabspathr
   r   appendr   playbook_pathsask_passwords_play_prereqsr   get_host_list_flush_cacher	   rZ   r`   rA   	enumerate_included_pathset_basedirrealpathrf   hosts	TypeErrorrd   rb   r=   	get_hostslenget_varscompilefilter_tagged_tasks	has_tasksra   rc   )r3   sshpass
becomepassrR   b_playbook_dirsr    resourceplaybook_collectionb_playbook_dirrQ   rO   rP   pbexresultspidxrn   pb_dir	host_listmsg	playhostshostrh   all_varsrY   rj   rk   rl   rm   r4   s                             @@@r5   ro   zPlaybookCLI.runW   sT   k4$& 
	
 / 	7H 5X>H#&.qk# ww~~h/&'Lx'WXXx0DMM"''(BSB[B[4\&'VYa'abb 'EX&N# '!#([pAq1r!s#N3&&~6+	7.  6E#2 ,0L
+wx/H$($6$6$8!Wj&-jII /3.@.@.B+	+ 	)W__X%>? ??=)i)9:  '//&*AY1A&*35 ((*gt$ C1 01Z= @A!*1W:!6 @1IC**6**4+>+>?!#!1!1"''//!J-2P!Q**62'$'HHTZZ$8	 2S1Wi4SSC ^F>SXXf-=>>C{3$'	(;(;DJJ(G$H	CtzzSVW`SaFbbb$- 7D<$#66C7 OOC("uHz2gook6R"$"??;7&4G+* $4#<#<$#<#G%)\\^ =E$)$=$=h$GE#(??#4 (#~e'<<G	= #??:6'+FLL,B'CH$MMO#'@499XCV'VVG0A@1C1J Nu % '$&	's   S55TTc                p    | j                         D ]#  }|j                         }|j                  |       % y N)
list_hostsre   clear_facts)rO   rP   r   hostnames       r5   r~   zPlaybookCLI._flush_cache   s3    ((* 	3D}}H((2	3r6   )__name__
__module____qualname____doc__rd   r%   r?   ro   staticmethodr~   __classcell__)r4   s   @r5   r   r      s6    W D\>&N` 3 3r6   r   c                .    t         j                  |        y r   )r   cli_executor)r   s    r5   mainr      s    T"r6   __main__r   )"
__future__r   ansible.clir   rp   rt   ansibler   r[   r   ansible.cli.argumentsr   r&   ansible.errorsr   "ansible.executor.playbook_executorr	   +ansible.module_utils.common.text.convertersr
   ansible.playbook.blockr   ansible.plugins.loaderr   ansible.utils.collection_loaderr   2ansible.utils.collection_loader._collection_finderr   r   ansible.utils.displayr   rA   r   r   r    r6   r5   <module>r      sg    #  	  "  < ' ? @ ( 6 C | ) )L3# L3^# zF r6   