
    Vhj                         d dl mZmZmZ eZdZdZd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 Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionab  
---
module: command
author: "Petr Klima (@qaxi)"
short_description: Run commands on remote Cisco SMB devices
description:
  - Sends arbitrary commands to an Cisco SMB 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.
options:
  commands:
    description:
      - List of commands to send to the remote Cisco SMB 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 has expired.
    required: true
    type: list
    elements: str
  wait_for:
    description:
      - List of conditions to evaluate against the output of the
        command. The task will wait for each condition to be true
        before moving forward. If the conditional is not true
        within the configured number of retries, the task fails.
        See examples.
    type: list
    elements: str
  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 wait_for must be satisfied.  If
        the value is set to C(any) then only one of the values must be
        satisfied.
    default: all
    type: str
    choices: ['any', '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) conditions.
    default: 10
    type: int
  interval:
    description:
      - Configures the interval in seconds to wait between retries
        of the command. If the command does not pass the specified
        conditions, the interval indicates how long to wait before
        trying the command again.
    default: 1
    type: int
ao  
- name: Run command on remote devices
  community.ciscosmb.command:
    commands: show version

- name: Run command and check to see if output contains PID
  community.ciscosmb.command:
    commands: show inventory
    wait_for: result[0] contains PID

- name: Run multiple commands on remote nodes
  community.ciscosmb.command:
    commands:
      - show version
      - show system

- name: Run multiple commands and evaluate the output
  community.ciscosmb.command:
    commands:
      - show version
      - show system
    wait_for:
      - result[0] contains Active-image
      - result[1] contains "System Up Time"
a  
stdout:
  description: The set of responses from the commands.
  returned: always apart from low level errors (such as action plugin)
  type: list
  sample: ['...', '...']
stdout_lines:
  description: The value of stdout split into a list.
  returned: always apart from low level errors (such as action plugin)
  type: list
  sample: [['...', '...'], ['...'], ['...']]
failed_conditions:
  description: The list of conditionals that have failed.
  returned: failed
  type: list
  sample: ['...', '...']
N)Conditional)run_commands)ciscosmb_argument_spec)AnsibleModule)string_typesc              #   v   K   | D ]0  }t        |t              rt        |      j                  d      }| 2 y w)N
)
isinstancer
   strsplit)stdoutitems     n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/ciscosmb/plugins/modules/command.pyto_linesr   x   s6      dL)t9??4(D
s   79c            
         t        t        ddd      t        dd      t        dddg      t        d	d
      t        dd
            } | j                  t               t        | d      }ddi}|j                  d   xs
 t               }|D cg c]  }t        |       }}|j                  d   }|j                  d   }|j                  d   }|dkD  rwt        ||j                  d         }	t        |      D ]-  }
 |
|	      s|dk(  rt               } n|j                  |
       / |sn t        j                  |       |dz  }|dkD  rw|r.|D 
cg c]  }
|
j                   }}
d}|j                  ||       |j                  d	t        t        |	            d        |j                  di | yc c}w c c}
w )z*main entry point for module execution
    listr   T)typeelementsrequired)r   r   allany)defaultchoices
   int)r   r      )commandswait_formatchretriesintervalF)argument_specsupports_check_modechangedr!   r#   r$   r"   r   r    z:One or more conditional statements have not been satisfied)msgfailed_conditions)r'   r   stdout_linesN )dictupdater   r	   paramsr   r   r   removetimesleepraw	fail_jsonr   	exit_json)r%   moduleresultr!   cconditionalsr#   r$   r"   	responsesr   r)   r(   s                r   mainr:      s    6EDA6E255%.9Re,ae,M /0/46F F}}Z(2DFH,45qKN5L5mmI&G}}Z(HMM'"E
A+ z)BC	& 	*DIE>#'6L##D)	* 

81 A+  2>?$TXX??JS4EF
MMXi01  FvC 6. @s   F7F<__main__)
__future__r   r   r   r   __metaclass__DOCUMENTATIONEXAMPLESRETURNr0   Qansible_collections.ansible.netcommon.plugins.module_utils.network.common.parsingr   Dansible_collections.community.ciscosmb.plugins.module_utils.ciscosmbr   r   ansible.module_utils.basicr	   ansible.module_utils.sixr
   r   r:   __name__r+       r   <module>rG      s\   
 C B9v4
$  i ] g 4 16r zF rF   