| 1 |
.. _dellemc.enterprise_sonic.sonic_command_module: |
| 2 |
|
| 3 |
|
| 4 |
************************************** |
| 5 |
dellemc.enterprise_sonic.sonic_command |
| 6 |
************************************** |
| 7 |
|
| 8 |
**Runs commands on devices running Enterprise SONiC** |
| 9 |
|
| 10 |
|
| 11 |
Version added: 1.0.0 |
| 12 |
|
| 13 |
.. contents:: |
| 14 |
:local: |
| 15 |
:depth: 1 |
| 16 |
|
| 17 |
|
| 18 |
Synopsis |
| 19 |
-------- |
| 20 |
- Runs commands on remote devices running Enterprise SONiC Distribution by Dell Technologies. Sends arbitrary commands to an Enterprise SONiC node and returns the results that are read from the device. This module includes an argument that causes the module to wait for a specific condition before returning or time out if the condition is not met. |
| 21 |
- This module does not support running commands in configuration mode. To configure SONiC devices, use :ref:`dellemc.enterprise_sonic.sonic_config <dellemc.enterprise_sonic.sonic_config_module>`. |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
Parameters |
| 27 |
---------- |
| 28 |
|
| 29 |
.. raw:: html |
| 30 |
|
| 31 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 32 |
<tr> |
| 33 |
<th colspan="1">Parameter</th> |
| 34 |
<th>Choices/<font color="blue">Defaults</font></th> |
| 35 |
<th width="100%">Comments</th> |
| 36 |
</tr> |
| 37 |
<tr> |
| 38 |
<td colspan="1"> |
| 39 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 40 |
<b>commands</b> |
| 41 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 42 |
<div style="font-size: small"> |
| 43 |
<span style="color: purple">list</span> |
| 44 |
/ <span style="color: purple">elements=string</span> |
| 45 |
/ <span style="color: red">required</span> |
| 46 |
</div> |
| 47 |
</td> |
| 48 |
<td> |
| 49 |
</td> |
| 50 |
<td> |
| 51 |
<div>List of commands to send to the remote Enterprise SONiC devices over the configured provider. The resulting output from the command is returned. If the <em>wait_for</em> argument is provided, the module is not returned until the condition is satisfied or the number of retries has expired. If a command sent to the device requires answering a prompt, it is possible to pass a dict containing <em>command</em>, <em>answer</em> and <em>prompt</em>. Common answers are 'yes' or "\r" (carriage return, must be double quotes). See examples.</div> |
| 52 |
</td> |
| 53 |
</tr> |
| 54 |
<tr> |
| 55 |
<td colspan="1"> |
| 56 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 57 |
<b>interval</b> |
| 58 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 59 |
<div style="font-size: small"> |
| 60 |
<span style="color: purple">integer</span> |
| 61 |
</div> |
| 62 |
</td> |
| 63 |
<td> |
| 64 |
<b>Default:</b><br/><div style="color: blue">1</div> |
| 65 |
</td> |
| 66 |
<td> |
| 67 |
<div>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.</div> |
| 68 |
</td> |
| 69 |
</tr> |
| 70 |
<tr> |
| 71 |
<td colspan="1"> |
| 72 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 73 |
<b>match</b> |
| 74 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 75 |
<div style="font-size: small"> |
| 76 |
<span style="color: purple">string</span> |
| 77 |
</div> |
| 78 |
</td> |
| 79 |
<td> |
| 80 |
<ul style="margin: 0; padding: 0"><b>Choices:</b> |
| 81 |
<li><div style="color: blue"><b>all</b> ←</div></li> |
| 82 |
<li>any</li> |
| 83 |
</ul> |
| 84 |
</td> |
| 85 |
<td> |
| 86 |
<div>The <em>match</em> argument is used in conjunction with the <em>wait_for</em> argument to specify the match policy. Valid values are <code>all</code> or <code>any</code>. If the value is set to <code>all</code> then all conditionals in the wait_for must be satisfied. If the value is set to <code>any</code> then only one of the values must be satisfied.</div> |
| 87 |
</td> |
| 88 |
</tr> |
| 89 |
<tr> |
| 90 |
<td colspan="1"> |
| 91 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 92 |
<b>retries</b> |
| 93 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 94 |
<div style="font-size: small"> |
| 95 |
<span style="color: purple">integer</span> |
| 96 |
</div> |
| 97 |
</td> |
| 98 |
<td> |
| 99 |
<b>Default:</b><br/><div style="color: blue">10</div> |
| 100 |
</td> |
| 101 |
<td> |
| 102 |
<div>Specifies the number of retries a command should be run before it is considered failed. The command is run on the target device every retry and evaluated against the <em>wait_for</em> conditions.</div> |
| 103 |
</td> |
| 104 |
</tr> |
| 105 |
<tr> |
| 106 |
<td colspan="1"> |
| 107 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 108 |
<b>wait_for</b> |
| 109 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 110 |
<div style="font-size: small"> |
| 111 |
<span style="color: purple">list</span> |
| 112 |
/ <span style="color: purple">elements=string</span> |
| 113 |
</div> |
| 114 |
</td> |
| 115 |
<td> |
| 116 |
</td> |
| 117 |
<td> |
| 118 |
<div>List of conditions to evaluate against the output of the command. The task waits 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.</div> |
| 119 |
</td> |
| 120 |
</tr> |
| 121 |
</table> |
| 122 |
<br/> |
| 123 |
|
| 124 |
|
| 125 |
Notes |
| 126 |
----- |
| 127 |
|
| 128 |
.. note:: |
| 129 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 130 |
- Supports ``check_mode``. |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
Examples |
| 135 |
-------- |
| 136 |
|
| 137 |
.. code-block:: yaml |
| 138 |
|
| 139 |
- name: Runs show version on remote devices |
| 140 |
dellemc.enterprise_sonic.sonic_command: |
| 141 |
commands: show version |
| 142 |
|
| 143 |
- name: Runs show version and checks to see if output contains 'Dell' |
| 144 |
dellemc.enterprise_sonic.sonic_command: |
| 145 |
commands: show version |
| 146 |
wait_for: result[0] contains Dell |
| 147 |
|
| 148 |
- name: Runs multiple commands on remote nodes |
| 149 |
dellemc.enterprise_sonic.sonic_command: |
| 150 |
commands: |
| 151 |
- show version |
| 152 |
- show interface |
| 153 |
|
| 154 |
- name: Runs multiple commands and evaluate the output |
| 155 |
dellemc.enterprise_sonic.sonic_command: |
| 156 |
commands: |
| 157 |
- 'show version' |
| 158 |
- 'show system' |
| 159 |
wait_for: |
| 160 |
- result[0] contains Dell |
| 161 |
- result[1] contains Hostname |
| 162 |
|
| 163 |
- name: Runs commands that require answering a prompt |
| 164 |
dellemc.enterprise_sonic.sonic_command: |
| 165 |
commands: |
| 166 |
- command: 'reload' |
| 167 |
prompt: '[confirm yes/no]: ?$' |
| 168 |
answer: 'no' |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
Return Values |
| 173 |
------------- |
| 174 |
Common return values are documented `here <https://docs.ansible.com/projects/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module: |
| 175 |
|
| 176 |
.. raw:: html |
| 177 |
|
| 178 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 179 |
<tr> |
| 180 |
<th colspan="1">Key</th> |
| 181 |
<th>Returned</th> |
| 182 |
<th width="100%">Description</th> |
| 183 |
</tr> |
| 184 |
<tr> |
| 185 |
<td colspan="1"> |
| 186 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 187 |
<b>failed_conditions</b> |
| 188 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 189 |
<div style="font-size: small"> |
| 190 |
<span style="color: purple">list</span> |
| 191 |
</div> |
| 192 |
</td> |
| 193 |
<td>failed</td> |
| 194 |
<td> |
| 195 |
<div>The list of conditionals that have failed.</div> |
| 196 |
<br/> |
| 197 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 198 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['...', '...']</div> |
| 199 |
</td> |
| 200 |
</tr> |
| 201 |
<tr> |
| 202 |
<td colspan="1"> |
| 203 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 204 |
<b>stdout</b> |
| 205 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 206 |
<div style="font-size: small"> |
| 207 |
<span style="color: purple">list</span> |
| 208 |
</div> |
| 209 |
</td> |
| 210 |
<td>always apart from low level errors (such as action plugin)</td> |
| 211 |
<td> |
| 212 |
<div>The set of responses from the commands.</div> |
| 213 |
<br/> |
| 214 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 215 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['...', '...']</div> |
| 216 |
</td> |
| 217 |
</tr> |
| 218 |
<tr> |
| 219 |
<td colspan="1"> |
| 220 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 221 |
<b>stdout_lines</b> |
| 222 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 223 |
<div style="font-size: small"> |
| 224 |
<span style="color: purple">list</span> |
| 225 |
</div> |
| 226 |
</td> |
| 227 |
<td>always apart from low level errors (such as action plugin)</td> |
| 228 |
<td> |
| 229 |
<div>The value of stdout split into a list.</div> |
| 230 |
<br/> |
| 231 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 232 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[['...', '...'], ['...'], ['...']]</div> |
| 233 |
</td> |
| 234 |
</tr> |
| 235 |
<tr> |
| 236 |
<td colspan="1"> |
| 237 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 238 |
<b>warnings</b> |
| 239 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 240 |
<div style="font-size: small"> |
| 241 |
<span style="color: purple">list</span> |
| 242 |
</div> |
| 243 |
</td> |
| 244 |
<td>always</td> |
| 245 |
<td> |
| 246 |
<div>The list of warnings (if any) generated by module based on arguments.</div> |
| 247 |
<br/> |
| 248 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 249 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['...', '...']</div> |
| 250 |
</td> |
| 251 |
</tr> |
| 252 |
</table> |
| 253 |
<br/><br/> |
| 254 |
|
| 255 |
|
| 256 |
Status |
| 257 |
------ |
| 258 |
|
| 259 |
|
| 260 |
Authors |
| 261 |
~~~~~~~ |
| 262 |
|
| 263 |
- Dhivya P (@dhivayp) |