Debian Codegraph @

ansible_collections/cisco/iosxr/docs/cisco.iosxr.iosxr_command_module.rst

raw
1 .. _cisco.iosxr.iosxr_command_module:
2
3
4 *************************
5 cisco.iosxr.iosxr_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 XR 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 :ref:`cisco.iosxr.iosxr_config <cisco.iosxr.iosxr_config_module>` to configure iosxr 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 iosxr 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.</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 &#x27;y&#x27; or &quot;\r&quot; (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 conditions, the interval indicates how 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>&nbsp;&larr;</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 wait_for 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">10</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> conditions.</div>
104 </td>
105 </tr>
106 <tr>
107 <td colspan="1">
108 <div class="ansibleOptionAnchor" id="parameter-"></div>
109 <b>wait_for</b>
110 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
111 <div style="font-size: small">
112 <span style="color: purple">list</span>
113 / <span style="color: purple">elements=string</span>
114 </div>
115 </td>
116 <td>
117 </td>
118 <td>
119 <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>
120 <div style="font-size: small; color: darkgreen"><br/>aliases: waitfor</div>
121 </td>
122 </tr>
123 </table>
124 <br/>
125
126
127 Notes
128 -----
129
130 .. note::
131 - Make sure the user has been authorized to execute commands terminal length 0, terminal width 512 and terminal exec prompt no-timestamp.
132 - This module works with ``network_cli``. See `the IOS-XR Platform Options <../network/user_guide/platform_iosxr.html>`_.
133 - This module does not support ``netconf`` connection.
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.iosxr.iosxr_command:
146 commands: show version
147
148 - name: run show version and check to see if output contains iosxr
149 cisco.iosxr.iosxr_command:
150 commands: show version
151 wait_for: result[0] contains IOS-XR
152
153 - name: run multiple commands on remote nodes
154 cisco.iosxr.iosxr_command:
155 commands:
156 - show version
157 - show interfaces
158 - {command: example command that prompts, prompt: expected prompt, answer: true}
159
160 - name: run multiple commands and evaluate the output
161 cisco.iosxr.iosxr_command:
162 commands:
163 - show version
164 - show interfaces
165 wait_for:
166 - result[0] contains IOS-XR
167 - result[1] contains Loopback0
168
169 - name: 'multiple prompt, multiple answer (mandatory check for all prompts)'
170 cisco.iosxr.iosxr_command:
171 commands:
172 - command: key config-key password-encryption
173 prompt:
174 - 'Enter old key :'
175 - 'Enter new key :'
176 - 'Enter confirm key :'
177 answer:
178 - test1234
179 - test12345
180 - test12345
181 check_all: true
182
183
184
185 Return Values
186 -------------
187 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:
188
189 .. raw:: html
190
191 <table border=0 cellpadding=0 class="documentation-table">
192 <tr>
193 <th colspan="1">Key</th>
194 <th>Returned</th>
195 <th width="100%">Description</th>
196 </tr>
197 <tr>
198 <td colspan="1">
199 <div class="ansibleOptionAnchor" id="return-"></div>
200 <b>failed_conditions</b>
201 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
202 <div style="font-size: small">
203 <span style="color: purple">list</span>
204 </div>
205 </td>
206 <td>failed</td>
207 <td>
208 <div>The list of conditionals that have failed</div>
209 <br/>
210 <div style="font-size: smaller"><b>Sample:</b></div>
211 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;...&#x27;, &#x27;...&#x27;]</div>
212 </td>
213 </tr>
214 <tr>
215 <td colspan="1">
216 <div class="ansibleOptionAnchor" id="return-"></div>
217 <b>stdout</b>
218 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
219 <div style="font-size: small">
220 <span style="color: purple">list</span>
221 </div>
222 </td>
223 <td>always apart from low level errors (such as action plugin)</td>
224 <td>
225 <div>The set of responses from the commands</div>
226 <br/>
227 <div style="font-size: smaller"><b>Sample:</b></div>
228 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;...&#x27;, &#x27;...&#x27;]</div>
229 </td>
230 </tr>
231 <tr>
232 <td colspan="1">
233 <div class="ansibleOptionAnchor" id="return-"></div>
234 <b>stdout_lines</b>
235 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
236 <div style="font-size: small">
237 <span style="color: purple">list</span>
238 </div>
239 </td>
240 <td>always apart from low level errors (such as action plugin)</td>
241 <td>
242 <div>The value of stdout split into a list</div>
243 <br/>
244 <div style="font-size: smaller"><b>Sample:</b></div>
245 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[[&#x27;...&#x27;, &#x27;...&#x27;], [&#x27;...&#x27;], [&#x27;...&#x27;]]</div>
246 </td>
247 </tr>
248 </table>
249 <br/><br/>
250
251
252 Status
253 ------
254
255
256 Authors
257 ~~~~~~~
258
259 - Ricardo Carrillo Cruz (@rcarrillocruz)