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: //lib/python3.9/site-packages/ansible/plugins/action/__pycache__/reboot.cpython-39.pyc
a

�)gXR�@s�ddlmZmZmZeZddlZddlZddlmZm	Z	ddl
mZmZddl
mZmZddlmZmZddlmZddlmZe�ZGd	d
�d
e�ZGdd�de�ZdS)
�)�absolute_import�division�print_functionN)�datetime�	timedelta)�AnsibleError�AnsibleConnectionFailure)�	to_native�to_text)�check_type_list�check_type_str)�
ActionBase)�Displayc@seZdZdS)�TimedOutExceptionN)�__name__�
__module__�__qualname__�rr�A/usr/lib/python3.9/site-packages/ansible/plugins/action/reboot.pyrsrcs eZdZdZed�ZdZdZdZdZ	dZ
dZdZd	Z
d
ZdZiZddd
d
d
dd
d�Zddd�Zdddeddddddd�
Zddd�Z�fdd�Zedd��Zedd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d;d3d4�Z"d5d6�Z#d<d7d8�Z$d=�fd9d:�	Z%�Z&S)>�ActionModuleF)	�boot_time_command�connect_timeout�msg�post_reboot_delay�pre_reboot_delay�reboot_command�reboot_timeout�search_paths�test_commandiXNrZwhoamiz#cat /proc/sys/kernel/random/boot_idzReboot initiated by AnsibleZshutdownz-r {delay_min} "{message}"Tz/sbin/sysctl kern.boottimezwho -bz/grep booted /var/log/vmksummary.log | tail -n 1)�freebsd�openbsd�macosx�solaris�sunos�vmkernel�aix�reboot)�alpiner$�z-r +{delay_min} "{message}"z-r +{delay_sec}s "{message}"z"-y -g {delay_sec} -i 6 "{message}"z-d {delay_sec}z-Fr)
r'ZvoidrZlinuxr!r r"r#r$r%Zwho)r"r$cstt|�j|i|��dS)N)�superr�__init__)�self�args�kwargs��	__class__rrr*VszActionModule.__init__cCs|�d|j�S)Nr)�_check_delay�DEFAULT_PRE_REBOOT_DELAY�r+rrrrYszActionModule.pre_reboot_delaycCs|�d|j�S)Nr)r0�DEFAULT_POST_REBOOT_DELAYr2rrrr]szActionModule.post_reboot_delaycCs4t|jj�||jj�|d|���}|dkr0d}|S)z)Ensure that the value is positive or zeroZ_secr)�int�_taskr,�get)r+�key�default�valuerrrr0as$zActionModule._check_delaycCsDt||�}|�|d|d|�|d|�|dt||����}|S)zXGet dist+version specific args first, then distribution, then family, lastly use default�name�version�family)�getattrr6)r+Z
variable_name�distributionZ
default_value�attrr9rrr�_get_value_from_factshs
���z"ActionModule._get_value_from_factsc
Cs�|jj�d�}|dur�zt|dd�}Wn4tyZ}ztdt|���WYd}~n
d}~00z|�dd�dWSty�YdS0n<|�	d|d	�}|j
d
}|jj�d|j�}|j|j
||d�SdS)
NrF�Zallow_conversion�-Invalid value given for 'reboot_command': %s.� �r(�SHUTDOWN_COMMAND_ARGS�DEFAULT_SHUTDOWN_COMMAND_ARGS�<r)Z	delay_sec�	delay_min�message)
r5r,r6r�	TypeErrorrr	�split�
IndexErrorr@r�DEFAULT_REBOOT_MESSAGE�format)r+r>r�er,rHZreboot_messagerrr�get_shutdown_command_argsts&

z&ActionModule.get_shutdown_command_argsc
Cs
i}t�dj|jjd��|j|dddid�}z�|�dd�rdtd	�t|d
��	�t|d��	����|dd
�
�|d<t|dd�d�d�|d<t|dd�
��|d<t�dj|jj|d��|WSt
�y}z td�|jd���WYd}~n
d}~00dS)Nz2{action}: running setup module to get distribution��actionzansible.legacy.setupZ
gather_subset�min��	task_varsZmodule_nameZmodule_args�failedFz1Failed to determine system distribution. {0}, {1}Z
module_stdoutZ
module_stderrZ
ansible_factsZansible_distributionr:Zansible_distribution_version�.rr;Zansible_os_familyr<z{action}: distribution: {dist})rRZdistz@Failed to get distribution information. Missing "{0}" in output.)�display�debugrNr5rR�_execute_moduler6rr	�strip�lowerr
rK�KeyErrorr,)r+rUr>Z
module_outputZkerrr�get_distribution�s(��zActionModule.get_distributionc
Cs>|jj�d�}|durnzt|dd�}Wn4tyZ}ztdt|���WYd}~n
d}~00|�dd�d}n|�d|d	�}|dd
kr�|Sgd�}|jj�d|�}zt	|�}Wn$ty�d
}t|�
|���Yn0t�dj
|jj
||d��|j|d||gdd�d�}	dd�|	dD�}
|
�s2td�
||���|
dSdS)NrFrArBrCrDr�SHUTDOWN_COMMANDS�DEFAULT_SHUTDOWN_COMMAND�/)z/sbinz/binz	/usr/sbinz/usr/binz/usr/local/sbinrz@'search_paths' must be a string or flat list of strings, got {0}zL{action}: running find module looking in {paths} to get path for "{command}")rR�command�pathszansible.legacy.find�any)rc�patternsZ	file_typerTcSsg|]}|d�qS)�pathr)�.0�xrrr�
<listcomp>��z5ActionModule.get_shutdown_command.<locals>.<listcomp>�filesz1Unable to find command "{0}" in search paths: {1})r5r,r6rrJrr	rKr@rrNrXrYrRrZ)r+rUr>rrOZshutdown_binZdefault_search_pathsr�err_msgZfind_result�	full_pathrrr�get_shutdown_command�sD&���z!ActionModule.get_shutdown_commandcCsD|j��D]4\}}|jj�|�dur
t�dj|||jjd��q
dS)NzGSince Ansible {version}, {arg} is no longer a valid option for {action})r;�argrR)	�DEPRECATED_ARGS�itemsr5r,r6rX�warningrNrR)r+ror;rrr�deprecated_args�s�zActionModule.deprecated_argsc
Cs|�d|d�}|jj�d�rp|jj�d�}zt|dd�Wn4tyn}ztdt|���WYd}~n
d}~00t�	dj
|jj|d��|j||j
d	�}|d
dkr�|d}|d
}tdj
|jj|d
t|�t|�d���t�	dj
|jj|d��d��|d��S)N�BOOT_TIME_COMMANDS�DEFAULT_BOOT_TIME_COMMANDrFrAz0Invalid value given for 'boot_time_command': %s.z5{action}: getting boot time with command: '{command}'�rRrb�Zsudoable�rcr�stdout�stderrzS{action}: failed to get host boot time info, rc: {rc}, stdout: {out}, stderr: {err})rRrx�out�errz {action}: last boot time: {boot})rRZboot)r@r5r,r6rrJrr	rXrYrNrR�_low_level_execute_command�DEFAULT_SUDOABLEr[)r+r>rrO�command_resultryrzrrr�get_system_boot_time�s(&� z!ActionModule.get_system_boot_timec
Cs�t�dj|jjd��|jj�d|jj�d|j��}|r�z4t�dj|jj|d��|j	�
d|�|j	��Wnty�t�
d�Yn0z|�|�}Wn(ty�}z|�WYd}~n
d}~00t|�d	ks�||kr�td
��dS)Nz,{action}: attempting to get system boot timerQrZconnect_timeout_secz,{action}: setting connect_timeout to {value}�rRr9�connection_timeoutzHConnection plugin does not allow the connection timeout to be overriddenrzboot time has not changed)rX�vvvrNr5rRr,r6�DEFAULT_CONNECT_TIMEOUTrY�_connection�
set_option�reset�AttributeErrorrrr��	Exception�len�
ValueError)r+r>�previous_boot_timerZcurrent_boot_timerOrrr�check_boot_time�szActionModule.check_boot_timecKs�|jj�d|�d|d��}t�dj|jjd��t�dj|jj|d��z|j	||j
d�}Wn6ty�z|j�
�Wnty�Yn0�Yn0|d	d
kr�djt|d�t|d
�d�}t|��t�dj|jjd��dS)Nr�
TEST_COMMANDS�DEFAULT_TEST_COMMANDz-{action}: attempting post-reboot test commandrQz9{action}: attempting post-reboot test command '{command}'rvrwrxrz Test command failed: {err} {out}rzry)r|r{z&{action}: system successfully rebooted)r5r,r6r@rXr�rNrRrYr}r~r�r�r�r�r	�RuntimeError)r+r>r-rrrrrr�run_test_commands$

�zActionModule.run_test_commandc

Csxt��t|d�}|duri}d}d}t��|k�rbz4|fd|i|��|rdt�dj|jj|d��WdSt�y^}	z�t	|	t
�r�z|j��Wnt
y�Yn0t
�dd�d}
d||
}||kr�||
}|�r8zt|	���d	}Wn.t�y}	zt|	�}WYd}	~	n
d}	~	00t�d
j|jj|||d��|d7}t�|�WYd}	~	q&d}	~	00q&td
j||d���dS)N)�secondsr�r>z{action}: {desc} success)rR�desci�����z@{action}: {desc} fail '{err}', retrying in {sleep:.4} seconds...)rRr�r|�sleeprDz0Timed out waiting for {desc} (timeout={timeout}))r��timeout)r�utcnowrrXrYrNr5rRr��
isinstancerr�r��randomZrandintr
�
splitlinesrL�timer�r)
r+rRr�action_descr>�
action_kwargsZmax_end_timeZ
fail_countZmax_fail_sleeprOZ
random_intZ
fail_sleep�errorrrr�do_until_success_or_timeoutsF
�"z(ActionModule.do_until_success_or_timeoutc	
Csi}i}|�||�}|�|�}d�||�}zBt�dj|jjd��t�dj|jj|d��|j||j	d�}WnHt
y�}z0t�dj|jjt|�d��d	|d
<WYd}~n
d}~00t�
�|d<|d
d	k�rd|d
<d|d<djt|d���t|d���d�|d<|Sd|d
<|S)Nz{0} {1}z{action}: rebooting server...rQz3{action}: rebooting server with command '{command}'rvrwz>{action}: AnsibleConnectionFailure caught and handled: {error}�rRr�rrx�startTrVF�rebootedz6Reboot command failed. Error was: '{stdout}, {stderr}'ryrz)ryrzr)rnrPrNrXr�r5rRrYr}r~rr
rr�r	r[)	r+rUr>�result�
reboot_resultZshutdown_commandZshutdown_command_argsrrOrrr�perform_rebootCs.
�
zActionModule.perform_rebootc	
Cspt�dj|jjd��i}�zt|jj�d|jj�d|j���}|j	|j
d|||d�z|j�d�}Wnt
yxYn�0||kr�z4t�dj|jj|d	��|j�d|�|j��WnDttfy�}z(t�d
j|jjt|�d��WYd}~n
d}~00|j	|jd|||d�d
|d<d
|d<WnFt�yj}z,d
|d<d
|d<t|�|d<|WYd}~Sd}~00|S)Nz{action}: validating rebootrQrZreboot_timeout_seczlast boot time check)rRr�rr>r�r�zC{action}: setting connect_timeout back to original value of {value}r�zE{action}: failed to reset connection_timeout back to default: {error}r�zpost-reboot test commandTr��changedrVr)rXr�rNr5rRr4r,r6�DEFAULT_REBOOT_TIMEOUTr�r�r��
get_optionr]rYr�r�rr�r
r�r)	r+r>�original_connection_timeoutr�r�rrrOZtoexrrr�validate_reboot`sT"����zActionModule.validate_rebootc
s�d|_d|_|jjdkr6d�|jj�}dddd|d�S|jjrJdddd�S|durVi}|�	�t
t|��||�}|�
dd�s�|�
d	d�r�|S|�|�}z|�|�}WnDty�}z,d|d	<d|d
<t|�|d<|WYd}~Sd}~00d}z(|j�d�}t�d
j|jj|d��Wn*t�y@t�dj|jjd��Yn0|�||�}	|	d	�rz|	}t��|	d}
|
j|d<|S|jdk�r�t�dj|jj|jd��t�dj|jj|jd��t�|j�|j||d|id�}t��|	d}
|
j|d<|S)NT�localz@Running {0} with local connection would reboot the control node.Fr)r��elapsedr�rVr)r�r�r�ZskippedrVr&rr�z6{action}: saving original connect_timeout of {timeout})rRr�z<{action}: connect_timeout connection option has not been setrQr�r�z/{action}: waiting an additional {delay} seconds)rRZdelayr�)r�)Z_supports_check_modeZ_supports_asyncr�Z	transportrNr5rRZ
_play_contextZ
check_modersr)r�runr6r^r�r�r
r�rXrYr]r�rr�r�rr�r�r�r�)r+�tmprUrr�r>r�rOr�r�r�r.rrr��sR



zActionModule.run)N)NN)NN)'rrrZTRANSFERS_FILES�	frozensetZ_VALID_ARGSr�r�r1r3r�rurMr`rFr~rprtr_rEr�r*�propertyrrr0r@rPr^rnrsr�r�r�r�r�r�r��
__classcell__rrr.rrsp����

-
)
5r)Z
__future__rrr�typeZ
__metaclass__r�r�rrZansible.errorsrrZansible.module_utils._textr	r
Z&ansible.module_utils.common.validationrrZansible.plugins.actionr
Zansible.utils.displayrrXr�rrrrrr�<module>s