| 1 |
.. _cisco.nxos.nxos_command_module: |
| 2 |
|
| 3 |
|
| 4 |
*********************** |
| 5 |
cisco.nxos.nxos_command |
| 6 |
*********************** |
| 7 |
|
| 8 |
**Run arbitrary command on Cisco NXOS devices** |
| 9 |
|
| 10 |
|
| 11 |
Version added: 1.0.0 |
| 12 |
|
| 13 |
.. contents:: |
| 14 |
:local: |
| 15 |
:depth: 1 |
| 16 |
|
| 17 |
|
| 18 |
Synopsis |
| 19 |
-------- |
| 20 |
- Sends an arbitrary command to an NXOS 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. |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
Parameters |
| 26 |
---------- |
| 27 |
|
| 28 |
.. raw:: html |
| 29 |
|
| 30 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 31 |
<tr> |
| 32 |
<th colspan="1">Parameter</th> |
| 33 |
<th>Choices/<font color="blue">Defaults</font></th> |
| 34 |
<th width="100%">Comments</th> |
| 35 |
</tr> |
| 36 |
<tr> |
| 37 |
<td colspan="1"> |
| 38 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 39 |
<b>commands</b> |
| 40 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 41 |
<div style="font-size: small"> |
| 42 |
<span style="color: purple">list</span> |
| 43 |
/ <span style="color: purple">elements=raw</span> |
| 44 |
/ <span style="color: red">required</span> |
| 45 |
</div> |
| 46 |
</td> |
| 47 |
<td> |
| 48 |
</td> |
| 49 |
<td> |
| 50 |
<div>The commands to send to the remote NXOS device. 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 retires as expired.</div> |
| 51 |
<div>The <em>commands</em> argument also accepts an alternative form that allows for complex values that specify the command to run and the output format to return. This can be done on a command by command basis. The complex argument supports the keywords <code>command</code> and <code>output</code> where <code>command</code> is the command to run and <code>output</code> is one of 'text' or 'json'.</div> |
| 52 |
<div>If a command sent to the device requires answering a prompt, it is possible to pass a dict containing command, answer and prompt. Common answers are 'y' or "\r" (carriage return, must be double quotes). See examples.</div> |
| 53 |
</td> |
| 54 |
</tr> |
| 55 |
<tr> |
| 56 |
<td colspan="1"> |
| 57 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 58 |
<b>interval</b> |
| 59 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 60 |
<div style="font-size: small"> |
| 61 |
<span style="color: purple">integer</span> |
| 62 |
</div> |
| 63 |
</td> |
| 64 |
<td> |
| 65 |
<b>Default:</b><br/><div style="color: blue">1</div> |
| 66 |
</td> |
| 67 |
<td> |
| 68 |
<div>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.</div> |
| 69 |
</td> |
| 70 |
</tr> |
| 71 |
<tr> |
| 72 |
<td colspan="1"> |
| 73 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 74 |
<b>match</b> |
| 75 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 76 |
<div style="font-size: small"> |
| 77 |
<span style="color: purple">string</span> |
| 78 |
</div> |
| 79 |
</td> |
| 80 |
<td> |
| 81 |
<ul style="margin: 0; padding: 0"><b>Choices:</b> |
| 82 |
<li>any</li> |
| 83 |
<li><div style="color: blue"><b>all</b> ←</div></li> |
| 84 |
</ul> |
| 85 |
</td> |
| 86 |
<td> |
| 87 |
<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 <em>wait_for</em> must be satisfied. If the value is set to <code>any</code> then only one of the values must be satisfied.</div> |
| 88 |
</td> |
| 89 |
</tr> |
| 90 |
<tr> |
| 91 |
<td colspan="1"> |
| 92 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 93 |
<b>retries</b> |
| 94 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 95 |
<div style="font-size: small"> |
| 96 |
<span style="color: purple">integer</span> |
| 97 |
</div> |
| 98 |
</td> |
| 99 |
<td> |
| 100 |
<b>Default:</b><br/><div style="color: blue">9</div> |
| 101 |
</td> |
| 102 |
<td> |
| 103 |
<div>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 <em>wait_for</em> conditionals.</div> |
| 104 |
<div>The commands are run once when <em>retries</em> is set to <code>0</code>.</div> |
| 105 |
</td> |
| 106 |
</tr> |
| 107 |
<tr> |
| 108 |
<td colspan="1"> |
| 109 |
<div class="ansibleOptionAnchor" id="parameter-"></div> |
| 110 |
<b>wait_for</b> |
| 111 |
<a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> |
| 112 |
<div style="font-size: small"> |
| 113 |
<span style="color: purple">list</span> |
| 114 |
/ <span style="color: purple">elements=string</span> |
| 115 |
</div> |
| 116 |
</td> |
| 117 |
<td> |
| 118 |
</td> |
| 119 |
<td> |
| 120 |
<div>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.</div> |
| 121 |
<div style="font-size: small; color: darkgreen"><br/>aliases: waitfor</div> |
| 122 |
</td> |
| 123 |
</tr> |
| 124 |
</table> |
| 125 |
<br/> |
| 126 |
|
| 127 |
|
| 128 |
Notes |
| 129 |
----- |
| 130 |
|
| 131 |
.. note:: |
| 132 |
- Limited Support for Cisco MDS |
| 133 |
- For information on using CLI and NX-API see the :ref:`NXOS Platform Options guide <nxos_platform_options>` |
| 134 |
- For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>` |
| 135 |
- For more information on using Ansible to manage Cisco devices see the `Cisco integration page <https://www.ansible.com/integrations/networks/cisco>`_. |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
Examples |
| 140 |
-------- |
| 141 |
|
| 142 |
.. code-block:: yaml |
| 143 |
|
| 144 |
- name: run show version on remote devices |
| 145 |
cisco.nxos.nxos_command: |
| 146 |
commands: show version |
| 147 |
|
| 148 |
- name: run show version and check to see if output contains Cisco |
| 149 |
cisco.nxos.nxos_command: |
| 150 |
commands: show version |
| 151 |
wait_for: result[0] contains Cisco |
| 152 |
|
| 153 |
- name: run multiple commands on remote nodes |
| 154 |
cisco.nxos.nxos_command: |
| 155 |
commands: |
| 156 |
- show version |
| 157 |
- show interfaces |
| 158 |
|
| 159 |
- name: run multiple commands and evaluate the output |
| 160 |
cisco.nxos.nxos_command: |
| 161 |
commands: |
| 162 |
- show version |
| 163 |
- show interfaces |
| 164 |
wait_for: |
| 165 |
- result[0] contains Cisco |
| 166 |
- result[1] contains loopback0 |
| 167 |
|
| 168 |
- name: run commands and specify the output format |
| 169 |
cisco.nxos.nxos_command: |
| 170 |
commands: |
| 171 |
- command: show version |
| 172 |
output: json |
| 173 |
|
| 174 |
- name: run commands that require answering a prompt |
| 175 |
cisco.nxos.nxos_command: |
| 176 |
commands: |
| 177 |
- configure terminal |
| 178 |
- command: no feature npv |
| 179 |
prompt: Do you want to continue |
| 180 |
answer: y |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
Return Values |
| 185 |
------------- |
| 186 |
Common return values are documented `here <https://docs.ansible.com/ansible/latest/reference_appendices/common_return_values.html#common-return-values>`_, the following are the fields unique to this module: |
| 187 |
|
| 188 |
.. raw:: html |
| 189 |
|
| 190 |
<table border=0 cellpadding=0 class="documentation-table"> |
| 191 |
<tr> |
| 192 |
<th colspan="1">Key</th> |
| 193 |
<th>Returned</th> |
| 194 |
<th width="100%">Description</th> |
| 195 |
</tr> |
| 196 |
<tr> |
| 197 |
<td colspan="1"> |
| 198 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 199 |
<b>failed_conditions</b> |
| 200 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 201 |
<div style="font-size: small"> |
| 202 |
<span style="color: purple">list</span> |
| 203 |
</div> |
| 204 |
</td> |
| 205 |
<td>failed</td> |
| 206 |
<td> |
| 207 |
<div>The list of conditionals that have failed</div> |
| 208 |
<br/> |
| 209 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 210 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['...', '...']</div> |
| 211 |
</td> |
| 212 |
</tr> |
| 213 |
<tr> |
| 214 |
<td colspan="1"> |
| 215 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 216 |
<b>stdout</b> |
| 217 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 218 |
<div style="font-size: small"> |
| 219 |
<span style="color: purple">list</span> |
| 220 |
</div> |
| 221 |
</td> |
| 222 |
<td>always apart from low level errors (such as action plugin)</td> |
| 223 |
<td> |
| 224 |
<div>The set of responses from the commands</div> |
| 225 |
<br/> |
| 226 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 227 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">['...', '...']</div> |
| 228 |
</td> |
| 229 |
</tr> |
| 230 |
<tr> |
| 231 |
<td colspan="1"> |
| 232 |
<div class="ansibleOptionAnchor" id="return-"></div> |
| 233 |
<b>stdout_lines</b> |
| 234 |
<a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> |
| 235 |
<div style="font-size: small"> |
| 236 |
<span style="color: purple">list</span> |
| 237 |
</div> |
| 238 |
</td> |
| 239 |
<td>always apart from low level errors (such as action plugin)</td> |
| 240 |
<td> |
| 241 |
<div>The value of stdout split into a list</div> |
| 242 |
<br/> |
| 243 |
<div style="font-size: smaller"><b>Sample:</b></div> |
| 244 |
<div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[['...', '...'], ['...'], ['...']]</div> |
| 245 |
</td> |
| 246 |
</tr> |
| 247 |
</table> |
| 248 |
<br/><br/> |
| 249 |
|
| 250 |
|
| 251 |
Status |
| 252 |
------ |
| 253 |
|
| 254 |
|
| 255 |
Authors |
| 256 |
~~~~~~~ |
| 257 |
|
| 258 |
- Peter Sprygada (@privateip) |