Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/network/f5/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyc

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlZddlm
Z
dd
lmZddlmZddlmZddlmZddlmZddlmZytddlmZddlmZddlmZddlmZddlmZddlmZddlm Z Wn�e!k
r�ddl"mZddl#mZddl#mZddl#mZddl#mZddl#mZddl#m Z nXyddl#m$Z$e%Z&Wne!k
re'Z&nXde(fd��YZ)defd��YZ*de(fd ��YZ+d!e+fd"��YZ,d#e+fd$��YZ-d%e(fd&��YZ.d'e(fd(��YZ/d)�Z0e1d*kr�e0�ndS(+i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontstableinterfacetstatust	certifiedtsupported_bys�
---
module: bigip_command
short_description: Run TMSH and BASH commands on F5 devices
description:
  - Sends a TMSH or BASH command to an BIG-IP node and returns the results
    read from the device. This module includes an argument that will cause
    the module to wait for a specific condition before returning or timing
    out if the condition is not met.
  - This module is B(not) idempotent, nor will it ever be. It is intended as
    a stop-gap measure to satisfy automation requirements until such a time as
    a real module has been developed to configure in the way you need.
  - If you are using this module, you should probably also be filing an issue
    to have a B(real) module created for your needs.
version_added: 2.4
options:
  commands:
    description:
      - The commands to send to the remote BIG-IP device over the
        configured provider. The resulting output from the command
        is returned. If the I(wait_for) argument is provided, the
        module is not returned until the condition is satisfied or
        the number of retries as expired.
      - Only C(tmsh) commands are supported. If you are piping or adding additional
        logic that is outside of C(tmsh) (such as grep'ing, awk'ing or other shell
        related things that are not C(tmsh), this behavior is not supported.
    required: True
    type: raw
  wait_for:
    description:
      - Specifies what to evaluate from the output of the command
        and what conditionals to apply.  This argument will cause
        the task to wait for a particular conditional to be true
        before moving forward. If the conditional is not true
        by the configured retries, the task fails. See examples.
    type: list
    aliases: ['waitfor']
  match:
    description:
      - The I(match) argument is used in conjunction with the
        I(wait_for) argument to specify the match policy. Valid
        values are C(all) or C(any). If the value is set to C(all)
        then all conditionals in the I(wait_for) must be satisfied. If
        the value is set to C(any) then only one of the values must be
        satisfied.
    type: str
    choices:
      - any
      - all
    default: all
  retries:
    description:
      - Specifies the number of retries a command should by tried
        before it is considered failed. The command is run on the
        target device every retry and evaluated against the I(wait_for)
        conditionals.
    type: int
    default: 10
  interval:
    description:
      - Configures the interval in seconds to wait between retries
        of the command. If the command does not pass the specified
        conditional, the interval indicates how to long to wait before
        trying the command again.
    type: int
    default: 1
  transport:
    description:
      - Configures the transport connection to use when connecting to the
        remote device. The transport argument supports connectivity to the
        device over cli (ssh) or rest.
    required: true
    choices:
        - rest
        - cli
    default: rest
    version_added: 2.5
  warn:
    description:
      - Whether the module should raise warnings related to command idempotency
        or not.
      - Note that the F5 Ansible developers specifically leave this on to make you
        aware that your usage of this module may be better served by official F5
        Ansible modules. This module should always be used as a last resort.
    default: True
    type: bool
    version_added: 2.6
  chdir:
    description:
      - Change into this directory before running the command.
    type: str
    version_added: 2.6
extends_documentation_fragment: f5
author:
  - Tim Rupp (@caphrim007)
  - Wojciech Wypior (@wojtek0806)
s4
- name: run show version on remote devices
  bigip_command:
    commands: show sys version
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  delegate_to: localhost

- name: run show version and check to see if output contains BIG-IP
  bigip_command:
    commands: show sys version
    wait_for: result[0] contains BIG-IP
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  register: result
  delegate_to: localhost

- name: run multiple commands on remote nodes
  bigip_command:
    commands:
      - show sys version
      - list ltm virtual
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  delegate_to: localhost

- name: run multiple commands and evaluate the output
  bigip_command:
    commands:
      - show sys version
      - list ltm virtual
    wait_for:
      - result[0] contains BIG-IP
      - result[1] contains my-vs
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  register: result
  delegate_to: localhost

- name: tmsh prefixes will automatically be handled
  bigip_command:
    commands:
      - show sys version
      - tmsh list ltm virtual
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  delegate_to: localhost

- name: Delete all LTM nodes in Partition1, assuming no dependencies exist
  bigip_command:
    commands:
      - delete ltm node all
    chdir: Partition1
    provider:
      server: lb.mydomain.com
      password: secret
      user: admin
  delegate_to: localhost
s
stdout:
  description: The set of responses from the commands.
  returned: always
  type: list
  sample: ['...', '...']
stdout_lines:
  description: The value of stdout split into a list.
  returned: always
  type: list
  sample: [['...', '...'], ['...'], ['...']]
failed_conditions:
  description: The list of conditionals that have failed.
  returned: failed
  type: list
  sample: ['...', '...']
warn:
  description: Whether or not to raise warnings about modification commands.
  returned: changed
  type: bool
  sample: True
N(t
AnsibleModule(tFailedConditionsError(tConditional(tComplexList(tto_list(tstring_types(tdeque(tF5RestClient(t
F5ModuleError(tAnsibleF5Parameters(tfq_name(tf5_argument_spec(ttransform_name(tis_cli(trun_commandstNoChangeReportercB`s/eZejd�ejd�gZd�ZRS(sThe requested.*already existss(Data Input Error: shared.*already existscC`s<x5|D]-}x$|jD]}|j|�rtSqWqWtS(s�Searches the response for something that looks like a change

        This method borrows heavily from Ansible's ``_find_prompt`` method
        defined in the ``lib/ansible/plugins/connection/network_cli.py::Connection``
        class.

        Arguments:
            response (string): The output from the command.

        Returns:
            bool: True when change is detected. False otherwise.
        (t	stdout_retsearchtTruetFalse(tselft	responsestresponsetregex((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytfind_no_change�s


(t__name__t
__module__tretcompileRR (((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�st
ParameterscB`s�eZddddgZd�Zed��Zd�Zd�Zd�Zd	�Z	ed
��Z
ed��Zed��Zed
��Z
ed��Zed��Zd�Zd�Zd�ZRS(tstdouttstdout_linestwarningstexecuted_commandscC`s]i}y>x$|jD]}t||�||<qW|j|�}|SWntk
rX|SXdS(N(treturnablestgetattrt_filter_paramst	Exception(Rtresultt
returnable((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt	to_returns
cC`sQ|jddkrgSt|jdt�r@|jdg}n
|jd}|S(Ntcommands(t_valuestNonet
isinstanceR
(RR.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytraw_commandss
cC`s�g}x�|D]�}tdddd�}|jdd�}|jdd�}|d|d<y|d|d<Wntk
rnX|j|�q
W|S(	Ntcommandttpipelinet's\'t|ii(tdicttreplacetsplitt
IndexErrortappend(RR1R.R6ttmpR8((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytconvert_commands&s
	
cC`s�g}xv|D]n}tdddd�}|jdd�}|d|d<y|d|d<Wntk
rmnX|j|�q
W|S(NR6R7R8R:ii(R;R=R>R?(RR1R.R6R@R8((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytconvert_commands_cli8s
	
cC`s^|ddkrZd}tj|d|d�|d<dj|d|d�j�|d<ndS(NR8R7s([$"])s\\\1s	{0} | {1}R6(R#tsubtformattstrip(RR6tescape_patterns((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytmerge_command_dictIscC`s;|ddkr7dj|d|d�j�|d<ndS(NR8R7s	{0} | {1}R6(RDRE(RR6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytmerge_command_dict_cliOscC`s�|j}|j|�}|jrBx|D]}|j|�q(Wnx|D]}|j|�qIWx|D]}|j|�qgWg|D]}|d^q�}|S(NR6(tnormalized_commandsRAtchdirtaddon_chdirt
addon_tmshRG(RR1R6txR.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt
rest_commandsSs		


cC`s�|j}|j|�}|jrBx|D]}|j|�q(Wn|jslx|D]}|j|�qRWnx|D]}|j|�qsWg|D]}|d^q�}|S(NR6(RIRBRJRKtis_tmshtaddon_tmsh_cliRH(RR1R6RMR.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytcli_commandsds		
	

cC`s(|jddkrdSt|jd�S(NRI(R2R3R(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRIvscC`sL|jddkrdS|jdjd�r8|jdSdj|jd�S(NRJt/s/{0}(R2R3t
startswithRD(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRJ|s
cC`s|j}t|j|�S(N(R5tmapt_ensure_tmsh_prefix(RR1((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt
user_commands�s	cC`s|jdpt�S(Ntwait_for(R2tlist(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRW�scC`sjd}|djd�ddkr2td��ntj|d|d�|d<dj|d�|d<dS(	Ns([$"])R6t"iisDouble quotes are unbalanceds\\\\\\\1stmsh -c \"{0}\"(tcountR-R#RCRD(RR6RF((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRL�s
cC`sG|djd�ddkr,td��ndj|d�|d<dS(NR6RYiisDouble quotes are unbalanceds
tmsh -c "{0}"(RZR-RD(RR6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRP�scC`s!dj|j|d�|d<dS(Nscd {0}; {1}R6(RDRJ(RR6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRK�s(R!R"R*R0tpropertyR5RARBRGRHRNRQRIRJRVRWRLRPRK(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR%s 	

						tBaseManagercB`sqeZd�Zd�Zd�Zd�Zd�Zed��Zd�Z	d�Z
d�Zd	�Zd
�Z
RS(cO`s�|jdd�|_t|jj�|_td|jj�|_|jji|jd6�td|j�|_	dddg|_
d	|_t�|_
dS(
NtmoduletparamsRXtshows$modify cli preference pager disabledtmodifytcreatetdelete(R`RaRb(tgetR3R]RR^tclientR%twanttupdatetchangest
valid_configstchanged_command_prefixesRXR((Rtargstkwargs((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt__init__�s	cC`sLt�}x<|D]4}t|t�r7|jd�}n|j|�qW|S(Ns
(RXR4R
R=R?(RR&tlinestitem((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt	_to_lines�s	
cC`sRt�}|j�}|j|jj��|jtd|��|j|�|S(Ntchanged(R;texecuteRfRgR0t_announce_warnings(RR.Rp((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytexec_module�s	
cC`s7|jdg�}x|D]}|jj|�qWdS(NR((tpopR]twarn(RR.R(twarning((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRr�s
c`sdx]t|�D]O\}�t�fd�|jD��r<dS|jjdj�dd!��q
WdS(Nc3`s|]}�j|�VqdS(N(RS(t.0RM(Rn(sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pys	<genexpr>�ss�Using "write" commands is not idempotent. You should use a module that is specifically made for that. If such a module does not exist, then please file a bug. The command in question is "{0}..."ii((t	enumeratetanyRhR(R?RD(RR1tindex((RnsL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytnotify_non_idempotent_commands�s	cC`sd|s
dSg}xM|D]E}|j�}|dd!dkrO|dj�}n|j|�qW|S(Niistmsh i(R3RER?(R5R.R6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytnormalize_commands�s
cC`s�g}|j|j�}x�t|�D]�\}}|jdd�}|dkrrd|dkrr|dcd7<n9|dkr�d|dkr�|djdd�|d<n|j|�q%W|S(Ntoutputsone-lineR6s	 one-linettextR7(t_transform_to_complex_commandsR1RxRtR3R<R?(RtresultsR1RzRnR}((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytparse_commands�scC`s�|jjr|jj}n,|j|jj�}|jji|d6�|sQtS|j|jj�|j�}|jj}g|jj	D]}t
|�^q�}|jjr�dSx�|dkrX|j
|�}|j|�xOt|�D]A}||�r�|jjdkrt�}Pn|j|�q�q�W|s8Pntj|jj�|d8}q�Wg|D]}|j^q`}d}	t|	|��|j|�}
i|d6|
d6|jd6}|jjr�|j|d	<ntd
|d|j�|_|j|�S(NRIiRyis;One or more conditional statements have not been satisfied.R&R'R)R(R^R](ReRIR|R5RfRR{R�tretriesRWR
R]t
check_modet_executet_check_known_errorsRXtmatchtremovettimetsleeptintervaltrawR	RoR1RuR(R%Rgtdetermine_change(RR.R1R�tctconditionalsRRntfailed_conditionsterrmsgR'Rg((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRq�sJ%
	
c`sFt�}|j|�rtSt�fd��jjD��rBtStS(Nc3`s'|]}|j�j�r|VqdS(N(RSRi(RwRM(R(sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pys	<genexpr>s(RR RRyReRIR(RRtchanger((RsL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�s	"cC`s0x)|D]!}d|krtd��qqWdS(Nsusage: tmshsrtmsh command printed its 'help' message instead of running your command. This usually indicates unbalanced quotes.(R(RRtresp((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR� s
c
C`sUtdtdt�dtdddddg��}t||j�}||�}|S(NR6tkeyR}tdefaultR~tchoicessone-line(R;RRR](RR1tspect	transformR.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR+s(R!R"RlRoRsRrR{tstaticmethodR|R�RqR�R�R(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR\�s			
				.		t	V1ManagercB`sAeZdZd�Zed��Zd�Zd�Zd�ZRS(s=Supports CLI (SSH) communication with the remote device

    cC`sG|jjrtdd�}ntdd�}|j|�|j|�S(NR6s$modify cli preference pager disableds)tmsh modify cli preference pager disabled(ReROR;texecute_on_device(RR1R6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�<s	
cC`s
|jjS(N(ReRQ(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR1HscC`sDy|jd�Wn,tk
r?}dt|�kr9tS�nXtS(Nstmsh -vs
Syntax Error:(R�R-tstrRR(Rtex((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyROLscC`s0|jji|j�d6�tt|�j�S(NRO(ReRfROtsuperR�Rq(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRqUscC`st|j|�}|S(N(RR](RR1R.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�Ys(	R!R"t__doc__R�R[R1RORqR�(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�8s				t	V2ManagercB`s/eZdZd�Zed��Zd�ZRS(s8Supports REST communication with the remote device

    cC`s)tdd�}|j|�|j|�S(NR6s)tmsh modify cli preference pager disabled(R;R�(RR1R6((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�bs	
cC`s
|jjS(N(ReRN(R((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR1isc
C`s>g}dj|jjd|jjd�}xt|�D]�}y�tddddj|d��}|jjj|d|�}|j�}d	|kr�d
j|d	�}|j|j	��nWn%t
k
r�}	tt|	���nXd|kr9|ddkr9d
|kr$t|d
��q6t|j
��q9q9W|S(Ns!https://{0}:{1}/mgmt/tm/util/bashtservertserver_portR6truntutilCmdArgss-c "{0}"tjsont
commandResultu{0}tcodei�tmessage(RDRdtproviderRR;tapitpostR�R?REt
ValueErrorRR�tcontent(
RR1RturiRnRjR�RR}R�((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�ms*
(R!R"R�R�R[R1R�(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR�^s	t
ModuleManagercB`s#eZd�Zd�Zd�ZRS(cO`s"||_|jdd�|_dS(NR](RkRcR3R](RRjRk((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRl�s	cC`sFt|j�r'tr'|jd�}n|jd�}|j�}|S(Ntv1tv2(RR]tHAS_CLI_TRANSPORTtget_managerRs(RtmanagerR.((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRs�s
cC`s6|dkrt|j�S|dkr2t|j�SdS(NR�R�(R�RkR�(Rttype((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR��s
(R!R"RlRsR�(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR��s		tArgumentSpeccB`seZd�ZRS(cC`s�t|_tdtdddt�dtddddg�d	td
ddd
dg�dtd
ddd�dtd
ddd�dtddd
ddddg�dtddd
d�dt��}i|_|jjt�|jj|�dS(NR1R�R�trequiredRWRXtaliasestwaitforR�R�tallR�RyR�i
tintR�it	transportR�tresttcliRutbooltyesRJ(Rtsupports_check_modeR;t
argument_specRfR(RR�((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyRl�s8						(R!R"Rl(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyR��scC`s�t�}td|jd|j�}y,td|�}|j�}|j|�Wn)tk
r{}|jdt	|��nXdS(NR�R�R]tmsg(
R�RR�R�R�Rst	exit_jsonRt	fail_jsonR�(R�R]tmmR�R�((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pytmain�s		t__main__(2t
__future__RRRR�t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNR#R�tansible.module_utils.basicRt+ansible.module_utils.network.common.parsingR	R
t)ansible.module_utils.network.common.utilsRRtansible.module_utils.sixR
tcollectionsRt%library.module_utils.network.f5.bigipRt&library.module_utils.network.f5.commonRRRRRRtImportErrort%ansible.module_utils.network.f5.bigipt&ansible.module_utils.network.f5.commonRRR�RtobjectRR%R\R�R�R�R�R�R!(((sL/usr/lib/python2.7/site-packages/ansible/modules/network/f5/bigip_command.pyt<module>s^


bF



��&+(	

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