Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/utilities/logic/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyc

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZmZmZdd
lmZeZdZyddlZe ZWne!k
rCej"�ZnXde#fd��YZ$de$fd��YZ%d�Z&d�Z'd�Z(d�Z)d�Z*d�Z+e,dkr�e+�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontstableinterfacetstatustcoretsupported_bys�
---
module: wait_for
short_description: Waits for a condition before continuing
description:
     - You can wait for a set amount of time C(timeout), this is the default if nothing is specified or just C(timeout) is specified.
       This does not produce an error.
     - Waiting for a port to become available is useful for when services are not immediately available after their init scripts return
       which is true of certain Java application servers.
     - It is also useful when starting guests with the M(virt) module and needing to pause until they are ready.
     - This module can also be used to wait for a regex match a string to be present in a file.
     - In Ansible 1.6 and later, this module can also be used to wait for a file to be available or
       absent on the filesystem.
     - In Ansible 1.8 and later, this module can also be used to wait for active connections to be closed before continuing, useful if a node
       is being rotated out of a load balancer pool.
     - For Windows targets, use the M(win_wait_for) module instead.
version_added: "0.7"
options:
  host:
    description:
      - A resolvable hostname or IP address to wait for.
    type: str
    default: 127.0.0.1
  timeout:
    description:
      - Maximum number of seconds to wait for, when used with another condition it will force an error.
      - When used without other conditions it is equivalent of just sleeping.
    type: int
    default: 300
  connect_timeout:
    description:
      - Maximum number of seconds to wait for a connection to happen before closing and retrying.
    type: int
    default: 5
  delay:
    description:
      - Number of seconds to wait before starting to poll.
    type: int
    default: 0
  port:
    description:
      - Port number to poll.
      - C(path) and C(port) are mutually exclusive parameters.
    type: int
  active_connection_states:
    description:
      - The list of TCP connection states which are counted as active connections.
    type: list
    default: [ ESTABLISHED, FIN_WAIT1, FIN_WAIT2, SYN_RECV, SYN_SENT, TIME_WAIT ]
    version_added: "2.3"
  state:
    description:
      - Either C(present), C(started), or C(stopped), C(absent), or C(drained).
      - When checking a port C(started) will ensure the port is open, C(stopped) will check that it is closed, C(drained) will check for active connections.
      - When checking for a file or a search string C(present) or C(started) will ensure that the file or string is present before continuing,
        C(absent) will check that file is absent or removed.
    type: str
    choices: [ absent, drained, present, started, stopped ]
    default: started
  path:
    description:
      - Path to a file on the filesystem that must exist before continuing.
      - C(path) and C(port) are mutually exclusive parameters.
    type: path
    version_added: "1.4"
  search_regex:
    description:
      - Can be used to match a string in either a file or a socket connection.
      - Defaults to a multiline regex.
    type: str
    version_added: "1.4"
  exclude_hosts:
    description:
      - List of hosts or IPs to ignore when looking for active TCP connections for C(drained) state.
    type: list
    version_added: "1.8"
  sleep:
    description:
      - Number of seconds to sleep between checks.
      - Before Ansible 2.3 this was hardcoded to 1 second.
    type: int
    default: 1
    version_added: "2.3"
  msg:
    description:
      - This overrides the normal error message from a failure to meet the required conditions.
    type: str
    version_added: "2.4"
notes:
  - The ability to use search_regex with a port connection was added in Ansible 1.7.
  - Prior to Ansible 2.4, testing for the absence of a directory or UNIX socket did not work correctly.
  - Prior to Ansible 2.4, testing for the presence of a file did not work correctly if the remote user did not have read access to that file.
  - Under some circumstances when using mandatory access control, a path may always be treated as being absent even if it exists, but
    can't be modified or created by the remote user either.
  - When waiting for a path, symbolic links will be followed.  Many other modules that manipulate files do not follow symbolic links,
    so operations on the path using other modules may not work exactly as expected.
seealso:
- module: wait_for_connection
- module: win_wait_for
- module: win_wait_for_process
author:
    - Jeroen Hoekx (@jhoekx)
    - John Jarvis (@jarv)
    - Andrii Radyk (@AnderEnder)
s�
- name: sleep for 300 seconds and continue with play
  wait_for:
    timeout: 300
  delegate_to: localhost

- name: Wait for port 8000 to become open on the host, don't start checking for 10 seconds
  wait_for:
    port: 8000
    delay: 10

- name: Waits for port 8000 of any IP to close active connections, don't start checking for 10 seconds
  wait_for:
    host: 0.0.0.0
    port: 8000
    delay: 10
    state: drained

- name: Wait for port 8000 of any IP to close active connections, ignoring connections for specified hosts
  wait_for:
    host: 0.0.0.0
    port: 8000
    state: drained
    exclude_hosts: 10.2.1.2,10.2.1.3

- name: Wait until the file /tmp/foo is present before continuing
  wait_for:
    path: /tmp/foo

- name: Wait until the string "completed" is in the file /tmp/foo before continuing
  wait_for:
    path: /tmp/foo
    search_regex: completed

- name: Wait until regex pattern matches in the file /tmp/foo and print the matched group
  wait_for:
    path: /tmp/foo
    search_regex: completed (?P<task>\w+)
  register: waitfor
- debug:
    msg: Completed {{ waitfor['groupdict']['task'] }}

- name: Wait until the lock file is removed
  wait_for:
    path: /var/lock/file.lock
    state: absent

- name: Wait until the process is finished and pid was destroyed
  wait_for:
    path: /proc/3466/status
    state: absent

- name: Output customized message when failed
  wait_for:
    path: /tmp/foo
    state: present
    msg: Timeout to find file /tmp/foo

# Do not assume the inventory_hostname is resolvable and delay 10 seconds at start
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
  wait_for:
    port: 22
    host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
    search_regex: OpenSSH
    delay: 10
  connection: local

# Same as above but you normally have ansible_connection set in inventory, which overrides 'connection'
- name: Wait 300 seconds for port 22 to become open and contain "OpenSSH"
  wait_for:
    port: 22
    host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
    search_regex: OpenSSH
    delay: 10
  vars:
    ansible_connection: local
st
elapsed:
  description: The number of seconds that elapsed while waiting
  returned: always
  type: int
  sample: 23
match_groups:
  description: Tuple containing all the subgroups of the match as returned by U(https://docs.python.org/2/library/re.html#re.MatchObject.groups)
  returned: always
  type: list
  sample: ['match 1', 'match 2']
match_groupdict:
  description: Dictionary containing all the named subgroups of the match, keyed by the subgroup name,
    as returned by U(https://docs.python.org/2/library/re.html#re.MatchObject.groupdict)
  returned: always
  type: dict
  sample:
    {
      'group': 'match'
    }
N(t
AnsibleModuletload_platform_subclasstmissing_required_lib(t	to_nativetTCPConnectionInfocB`sleZdZdZdZidej6dej6Z	idd6dd6Z
d�Zd	�Zd
�Z
d�ZRS(
s�
    This is a generic TCP Connection Info strategy class that relies
    on the psutil module, which is not ideal for targets, but necessary
    for cross platform support.

    A subclass may wish to override some or all of these methods.
      - _get_exclude_ips()
      - get_active_connections()

    All subclasses MUST define platform and distribution (which may be None).
    tGenerics0.0.0.0s::s::fffftprefixs::ffff:0.0.0.0t	match_allcO`stt||�S(N(R	R(tclstargstkwargs((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyt__new__scC`sp||_t|jd�|_t|jjd�|_|j�|_tsl|j	dt
d�dt�ndS(Nthosttporttmsgtpsutilt	exception(tmodulet_convert_host_to_iptparamstipstintRt_get_exclude_ipstexclude_ipst
HAS_PSUTILt	fail_jsonR
tPSUTIL_IMP_ERR(tselfR((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyt__init__s	cC`sM|jjd}g}|dk	rIx$|D]}|jt|��q)Wn|S(Nt
exclude_hosts(RRtNonetextendR(R#R%RR((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyRs
c		C`s�d}x�tj�D]�}y:t|d�r@|jdd�}n|jdd�}Wntjk
rlqnXx?|D]7}|j|jjdkr�qtnt|d�r�|j	\}}n|j
\}}|j|kr�qtnt|d�r�|j\}}n|j
\}}|j|f|jkr,qtnt|j|f|jk|j|j|jf|jk|j|jd�o�|j|jd	f|jkf�rt|d
7}qtqtWqW|S(Nitget_connectionstkindtinettactive_connection_statest
local_addresstremote_addressRRi(Rtprocess_iterthasattrR(tconnectionstErrorRRRR,tladdrRR-traddrtfamilyRtanyRt
match_all_ipst
startswithtipv4_mapped_ipv6_address(	R#tactive_connectionstpR0tconntlocal_ipt
local_portt	remote_iptremote_port((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pytget_active_connections_count!s8
%N(t__name__t
__module__t__doc__tplatformR&tdistributiontsockettAF_INETtAF_INET6R6R8RR$RR@(((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyR�s


			tLinuxTCPConnectionInfocB`s�eZdZdZdZidej6dej6Z	idej6dej6Z
idd6dd	6Zd
ZdZ
dZd
�Zd�Zd�ZRS(s�
    This is a TCP Connection Info evaluation strategy class
    that utilizes information from Linux's procfs. While less universal,
    does allow Linux targets to not require an additional library.
    tLinuxs
/proc/net/tcps/proc/net/tcp6t00000000t 00000000000000000000000000000000t0000000000000000FFFF0000Rt 0000000000000000FFFF000000000000RiiicC`sL||_t|jd�|_dt|jd�|_|j�|_dS(NRs%0.4XR(Rt_convert_host_to_hexRRRRRR(R#R((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyR$as	cC`sM|jjd}g}|dk	rIx$|D]}|jt|��q)Wn|S(NR%(RRR&R'RO(R#R%RR((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyRgs
c
	C`s�d}x�|jj�D]�}tjj|j|�s;qnt|j|�}xV|j�D]H}|j�j�}||j	dkr�q[n||j
g|jjdD]}t
|�^q�kr�q[n||j	jd�\}}|j|kr�q[n||jjd�\}}	||f|jkr0q[nt||f|jk||j|f|jk|j|jd�o�||jdf|jkf�r[|d7}q[q[W|j�qW|S(NiR,R+t:RRi(tsource_filetkeystostpathtisfiletopent	readlineststriptsplittlocal_address_fieldtconnection_state_fieldRRtget_connection_state_idRtremote_address_fieldRR5RR6R7R8tclose(
R#R9R4tfttcp_connectiont_connection_stateR<R=R>R?((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyR@os4
,"N(RARBRCRDR&RERFRGRHRQR6R8RZR]R[R$RR@(((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyRIHs$




		c	C`s�tj|dddtj�}g}xf|D]^\}}}}}|d}|j||f�|tjkr+|jtjd|f�q+q+W|S(s�
    Perform forward DNS resolution on host, IP will give the same IP

    Args:
        host: String with either hostname, IPv4, or IPv6 address

    Returns:
        List of tuples containing address family and IP
    iPis::ffff:(RFtgetaddrinfotSOL_TCPtappendRGRH(	RtaddrinfoRR4tsocktypetprotot	canonnametsockaddrtip((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyR�s

!c	C`s�g}|dk	r�x�t|�D]�\}}tjtj||��}d}x\tdt|�d�D]B}|||d!}tjt	|dd��}d||f}qeW|j
||f�qWn|S(ss
    Convert the provided host to the format in /proc/net/tcp*

    /proc/net/tcp uses little-endian four byte hex for ipv4
    /proc/net/tcp6 uses little-endian per 4B word for ipv6

    Args:
        host: String with either hostname, IPv4, or IPv6 address

    Returns:
        List of tuples containing address family and the
        little-endian converted host
    tiitbaseis%s%08XN(R&Rtbinasciitb2a_hexRFt	inet_ptontrangetlentntohlRRd(	RRR4Rjthexip_nfthexip_hftit
ipgroup_nft
ipgroup_hf((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyRO�scC`sytjdkr]t|�d\}}tj|tj�}|j|�|j||f�ntj||f|�}|S(s�
    Connect to a 2-tuple (host, port) and return
    the socket object.

    Args:
        2-tuple (host, port) and connection timeout
    Returns:
        Socket object
    iii(ii(tsystversion_infoRRFtSOCK_STREAMt
settimeouttconnecttcreate_connection(RRtconnect_timeoutR4t_tconnect_socket((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyt_create_connection�s

cC`s)|jd|j|jddddS(Ngiii
ii@Bi@B(tmicrosecondstsecondstdays(t	timedelta((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyt_timedelta_total_seconds�s
cC`s8idd6dd6dd6dd6d	d
6dd6}||S(
Nt01tESTABLISHEDt02tSYN_SENTt03tSYN_RECVt04t	FIN_WAIT1t05t	FIN_WAIT2t06t	TIME_WAIT((tstatetconnection_state_id((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyR\�s
cC`s�	tdtdtdddd�dtdddd	�d
tdddd�dtdddd
�dtdd�dtdddddddddg�dtdd�dtdd�dtddddddddddg�d tdd�d!tdddd"�d#tdd���}|jd}|jd}|jd
}|jd}|jd}|jd}|jd}|jd}|jd#}	|dk	r�tj|tj�}
nd}
i}d:}|r�|r�|jd#d$d%d
�n|r|dkr|jd#d&d%d
�n|r=|dkr=|jd#d'd%d
�n|jd dk	ru|dkru|jd#d(d%d
�nxQ|jdD]B}
yt|
�Wq�t	k
r�|jd#d)|
d%d
�q�Xq�Wt
j
j�}|r�tj
|�n|r|r|dkrtj
|�n5|d;krg|t
jd*|�}xt
j
j�|kr�|r�ytj|tj�stPnWq�tk
r�Pq�XnN|r�y0t|||�}|jtj�|j�Wq�t	k
r�Pq�Xntj
|jd!�q=Wt
j
j�|}|r8|jd#|	p(d+||fd%|j�qM	|rM	|jd#|	pTd,|d%|j�qM	n�|d<kr�|t
jd*|�}x�t
j
j�|kr�|r�ytj|�Wndtk
r}|jd-kr�t
j
j�|}|jd#|	pd.||jfd%|j�q�q�X|
s)Pnyzt|�}z\tj|
|j��}|r�|j �rt|j �}n|j!�r�|j!�}nPnWd|j�XWq�tk
r�q�Xn�|r�t"j#t$|t
j
j���}yt||t%||��}Wnt	k
rq�X|
r<d/}t&}x�t
j
j�|kr�t"j#t$|t
j
j���}t'j'|ggg|�\}}}|s�q*n|j(d0�}|s�Pn|t)|d1d2�7}tj|
|�r*t*}Pq*q*Wy|jtj�Wn.tj+k
r$}|jtj,kr/�q/nX|j�|r�Pq�q�y|jtj�Wn.tj+k
r�}|jtj,kr��q�nX|j�Pntj
|jd!�q�Wt
j
j�|}|r!|r�|jd#|	p�d3|||fd%|j�q|jd#|	pd4||fd%|j�qM	|rM	|rY|jd#|	pId5||fd%|j�q|jd#|	pod6|d%|j�qM	n�|dkrM	|t
jd*|�}t-|�}x�t
j
j�|kr
	y|j.�d
kr�PnWntk
r�nXtj
|jd!�q�Wt
j
j�|}|jd#|	p=	d7||fd%|j�nt
j
j�|}|j/d|d|d|d8|d9|d|d%|j�dS(=Nt
argument_specRttypetstrtdefaults	127.0.0.1ttimeoutRi,R~itdelayiRR+tlistR�R�R�R�R�R�RTtsearch_regexR�tstartedtchoicestabsenttdrainedtpresenttstoppedR%tsleepiRs:port and path parameter can not both be passed to wait_fortelapsedsLstate=stopped should only be used for checking a port in the wait_for modulesLstate=drained should only be used for checking a port in the wait_for modules/exclude_hosts should only be with state=draineds,unknown active_connection_state (%s) definedR�s'Timeout when waiting for %s:%s to stop.s)Timeout when waiting for %s to be absent.isFailed to stat %s, %sRkiterrorstsurrogate_or_stricts2Timeout when waiting for search string %s in %s:%ssTimeout when waiting for %s:%ss/Timeout when waiting for search string %s in %ss Timeout when waiting for file %ss'Timeout when waiting for %s:%s to draintmatch_groupstmatch_groupdict((R�R�(R�R�(0RtdictRR&tretcompilet	MULTILINER!R\t	ExceptiontdatetimetutcnowttimeR�R�RStaccesstF_OKtIOErrorR�tshutdownRFt	SHUT_RDWRR^R�tstattOSErrorterrnotstrerrorRVtsearchtreadt	groupdicttgroupstmathtceilR�tmintFalsetselecttrecvRtTrueterrortENOTCONNRR@t	exit_json(RRR�R~R�RR�RTR�Rtcompiled_search_reR�R�RatstarttendtsR�teR_R�talt_connect_timeouttdatatmatchedtmax_timeouttreadabletwtresponsettcpconns((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pytmain�s4'*









"

,)3
"
"$



/,,)
,-t__main__(-t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRmR�R�R�RSR�R�RFRxR�t	tracebacktansible.module_utils.basicRR	R
tansible.module_utils._textRR�R R&R"RR�tImportErrort
format_exctobjectRRIRROR�R�R\R�RA(((sL/usr/lib/python2.7/site-packages/ansible/modules/utilities/logic/wait_for.pyt<module>sJ


jN

RE						�

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]