Debian Codegraph @

ansible_collections/cisco/ios/docs/cisco.ios.ios_command_module.rst

raw
1 .. _cisco.ios.ios_command_module:
2
3
4 *********************
5 cisco.ios.ios_command
6 *********************
7
8 **Module to run commands on remote devices.**
9
10
11 Version added: 1.0.0
12
13 .. contents::
14 :local:
15 :depth: 1
16
17
18 Synopsis
19 --------
20 - Sends arbitrary commands to an ios 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 - This module does not support running commands in configuration mode. Please use `ios_config <https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_config_module.html#ansible-collections-cisco-ios-ios-config-module>`_ to configure IOS devices.
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=raw</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 ios device 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 &#x27;y&#x27; or &quot;\r&quot; (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>any</li>
82 <li><div style="color: blue"><b>all</b>&nbsp;&larr;</div></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">9</div>
100 </td>
101 <td>
102 <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> 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 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.</div>
119 <div style="font-size: small; color: darkgreen"><br/>aliases: waitfor</div>
120 </td>
121 </tr>
122 </table>
123 <br/>
124
125
126 Notes
127 -----
128
129 .. note::
130 - Tested against Cisco IOSXE Version 17.3 on CML.
131 - This module works with connection ``network_cli``. See https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html
132 - For more information on using Ansible to manage network devices see the :ref:`Ansible Network Guide <network_guide>`
133 - For more information on using Ansible to manage Cisco devices see the `Cisco integration page <https://www.ansible.com/integrations/networks/cisco>`_.
134
135
136
137 Examples
138 --------
139
140 .. code-block:: yaml
141
142 - name: Run show version on remote devices
143 cisco.ios.ios_command:
144 commands: show version
145
146 # output-
147
148 # ok: [iosxeappliance] => {
149 # "changed": false,
150 # "invocation": {
151 # "module_args": {
152 # "commands": [
153 # "show version"
154 # ],
155 # "interval": 1,
156 # "match": "all",
157 # "retries": 10,
158 # "wait_for": null
159 # }
160 # },
161 # "stdout": [
162 # "Cisco IOS XE Software, Version 17.03.04a\nCisco IOS Software [Amsterdam], Virtual XE Software ... register is 0x2102"
163 # ],
164 # "stdout_lines": [
165 # [
166 # "Cisco IOS XE Software, Version 17.03.04a",
167 # "Cisco IOS Software [Amsterdam], Virtual XE Software",
168 # "..."
169 # "Configuration register is 0x2102"
170 # ]
171 # ]
172 # }
173
174 - name: Run show version and check to see if output contains IOS
175 cisco.ios.ios_command:
176 commands: show version
177 wait_for: result[0] contains IOS
178
179 # output-
180
181 # ok: [iosxeappliance] => {
182 # "changed": false,
183 # "invocation": {
184 # "module_args": {
185 # "commands": [
186 # "show version"
187 # ],
188 # "interval": 1,
189 # "match": "all",
190 # "retries": 10,
191 # "wait_for": [
192 # "result[0] contains IOS"
193 # ]
194 # }
195 # },
196 # "stdout": [
197 # "Cisco IOS XE Software, Version 17.03.04a\nCisco IOS Software [Amsterdam], Virtual XE Software ... register is 0x2102"
198 # ],
199 # "stdout_lines": [
200 # [
201 # "Cisco IOS XE Software, Version 17.03.04a",
202 # "Cisco IOS Software [Amsterdam], Virtual XE Software",
203 # "..."
204 # "Configuration register is 0x2102"
205 # ]
206 # ]
207 # }
208
209 - name: Run multiple commands on remote nodes
210 cisco.ios.ios_command:
211 commands:
212 - show version
213 - show interfaces
214
215 # output-
216
217 # ok: [iosxeappliance] => {
218 # "changed": false,
219 # "invocation": {
220 # "module_args": {
221 # "commands": [
222 # "show version",
223 # "show interfaces"
224 # ],
225 # "interval": 1,
226 # "match": "all",
227 # "retries": 10,
228 # "wait_for": null
229 # }
230 # },
231 # "stdout": [
232 # "Cisco IOS XE Software, Version 17.03.04a\nCisco IOS Software [Amsterdam], Virtual XE Software Configuration register is 0x2102",
233 # "Loopback999 is up, line protocol is up ...failures, 0 output buffers swapped out"
234 # ],
235 # "stdout_lines": [
236 # [
237 # "Cisco IOS XE Software, Version 17.03.04a",
238 # "Cisco IOS Software [Amsterdam], Virtual XE Software",
239 # "..."
240 # "Configuration register is 0x2102"
241 # ],
242 # [
243 # "Loopback999 is up, line protocol is up ",
244 # " Hardware is Loopback",
245 # " Description: this is a test",
246 # " MTU 1514 bytes, BW 8000000 Kbit/sec, DLY 5000 usec, ",
247 # " reliability 255/255, txload 1/255, rxload 1/255",
248 # " Encapsulation LOOPBACK, loopback not set",
249 # " Keepalive set (10 sec)",
250 # " Last input never, output never, output hang never",
251 # " Last clearing of \"show interface\" counters never",
252 # " Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0",
253 # " Queueing strategy: fifo",
254 # " Output queue: 0/0 (size/max)",
255 # " 5 minute input rate 0 bits/sec, 0 packets/sec",
256 # " 5 minute output rate 0 bits/sec, 0 packets/sec",
257 # " 0 packets input, 0 bytes, 0 no buffer",
258 # " Received 0 broadcasts (0 IP multicasts)",
259 # " 0 runts, 0 giants, 0 throttles ",
260 # " 0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort",
261 # " 0 packets output, 0 bytes, 0 underruns",
262 # " Output 0 broadcasts (0 IP multicasts)",
263 # " 0 output errors, 0 collisions, 0 interface resets",
264 # " 0 unknown protocol drops",
265 # " 0 output buffer failures, 0 output buffers swapped out"
266 # ]
267 # ]
268 # }
269
270 - name: Run multiple commands and evaluate the output
271 cisco.ios.ios_command:
272 commands:
273 - show version
274 - show interfaces
275 wait_for:
276 - result[0] contains IOS
277 - result[1] contains Loopback0
278
279 # output-
280 # failed play as result[1] contains Loopback0 is false
281
282 # fatal: [iosxeappliance]: FAILED! => {
283 # "changed": false,
284 # "failed_conditions": [
285 # "result[1] contains Loopback0"
286 # ],
287 # "invocation": {
288 # "module_args": {
289 # "commands": [
290 # "show version",
291 # "show interfaces"
292 # ],
293 # "interval": 1,
294 # "match": "all",
295 # "retries": 10,
296 # "wait_for": [
297 # "result[0] contains IOS",
298 # "result[1] contains Loopback0"
299 # ]
300 # }
301 # },
302 # "msg": "One or more conditional statements have not been satisfied"
303 # }
304
305 - name: Run commands that require answering a prompt
306 cisco.ios.ios_command:
307 commands:
308 - command: "clear counters GigabitEthernet2"
309 prompt: 'Clear "show interface" counters on this interface \[confirm\]'
310 answer: "y"
311 - command: "clear counters GigabitEthernet3"
312 prompt: "[confirm]"
313 answer: "\r"
314
315 # output-
316
317 # ok: [iosxeappliance] => {
318 # "changed": false,
319 # "invocation": {
320 # "module_args": {
321 # "commands": [
322 # {
323 # "answer": "y",
324 # "check_all": false,
325 # "command": "clear counters GigabitEthernet2",
326 # "newline": true,
327 # "output": null,
328 # "prompt": "Clear \"show interface\" counters on this interface \\[confirm\\]",
329 # "sendonly": false
330 # },
331 # {
332 # "answer": "\r",
333 # "check_all": false,
334 # "command": "clear counters GigabitEthernet3",
335 # "newline": true,
336 # "output": null,
337 # "prompt": "[confirm]",
338 # "sendonly": false
339 # }
340 # ],
341 # "interval": 1,
342 # "match": "all",
343 # "retries": 10,
344 # "wait_for": null
345 # }
346 # },
347 # "stdout": [
348 # "Clear \"show interface\" counters on this interface [confirm]y",
349 # "Clear \"show interface\" counters on this interface [confirm]"
350 # ],
351 # "stdout_lines": [
352 # [
353 # "Clear \"show interface\" counters on this interface [confirm]y"
354 # ],
355 # [
356 # "Clear \"show interface\" counters on this interface [confirm]"
357 # ]
358 # ]
359 # }
360
361 - name: Run commands with complex values like special characters in variables
362 cisco.ios.ios_command:
363 commands:
364 ["{{ 'test aaa group TEST ' ~ user ~ ' ' ~ password ~ ' new-code' }}"]
365 vars:
366 user: "dummy"
367 password: "!dummy"
368
369 # ok: [iosxeappliance] => {
370 # "changed": false,
371 # "invocation": {
372 # "module_args": {
373 # "commands": [
374 # "test aaa group group test !dummy new-code"
375 # ],
376 # "interval": 1,
377 # "match": "all",
378 # "retries": 10,
379 # "wait_for": null
380 # }
381 # },
382 # "stdout": [
383 # "User was successfully authenticated."
384 # ],
385 # "stdout_lines": [
386 # [
387 # "User was successfully authenticated."
388 # ]
389 # ]
390 # }
391
392
393
394 Return Values
395 -------------
396 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:
397
398 .. raw:: html
399
400 <table border=0 cellpadding=0 class="documentation-table">
401 <tr>
402 <th colspan="1">Key</th>
403 <th>Returned</th>
404 <th width="100%">Description</th>
405 </tr>
406 <tr>
407 <td colspan="1">
408 <div class="ansibleOptionAnchor" id="return-"></div>
409 <b>failed_conditions</b>
410 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
411 <div style="font-size: small">
412 <span style="color: purple">list</span>
413 </div>
414 </td>
415 <td>failed</td>
416 <td>
417 <div>The list of conditionals that have failed</div>
418 <br/>
419 <div style="font-size: smaller"><b>Sample:</b></div>
420 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;...&#x27;, &#x27;...&#x27;]</div>
421 </td>
422 </tr>
423 <tr>
424 <td colspan="1">
425 <div class="ansibleOptionAnchor" id="return-"></div>
426 <b>stdout</b>
427 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
428 <div style="font-size: small">
429 <span style="color: purple">list</span>
430 </div>
431 </td>
432 <td>always apart from low level errors (such as action plugin)</td>
433 <td>
434 <div>The set of responses from the commands</div>
435 <br/>
436 <div style="font-size: smaller"><b>Sample:</b></div>
437 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;...&#x27;, &#x27;...&#x27;]</div>
438 </td>
439 </tr>
440 <tr>
441 <td colspan="1">
442 <div class="ansibleOptionAnchor" id="return-"></div>
443 <b>stdout_lines</b>
444 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
445 <div style="font-size: small">
446 <span style="color: purple">list</span>
447 </div>
448 </td>
449 <td>always apart from low level errors (such as action plugin)</td>
450 <td>
451 <div>The value of stdout split into a list</div>
452 <br/>
453 <div style="font-size: smaller"><b>Sample:</b></div>
454 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[[&#x27;...&#x27;, &#x27;...&#x27;], [&#x27;...&#x27;], [&#x27;...&#x27;]]</div>
455 </td>
456 </tr>
457 </table>
458 <br/><br/>
459
460
461 Status
462 ------
463
464
465 Authors
466 ~~~~~~~
467
468 - Peter Sprygada (@privateip)