1.. _ansible.netcommon.cli_command_module: 2 3 4***************************** 5ansible.netcommon.cli_command 6***************************** 7 8**Run a cli command on cli-based network devices** 9 10 11Version added: 1.0.0 12 13.. contents:: 14 :local: 15 :depth: 1 16 17 18Synopsis 19-------- 20- Sends a command to a network device and returns the result read from the device. 21 22 23 24 25Parameters 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>answer</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=string</span> 44 </div> 45 </td> 46 <td> 47 </td> 48 <td> 49 <div>The answer to reply with if <em>prompt</em> is matched. The value can be a single answer or a list of answer for multiple prompts. In case the command execution results in multiple prompts the sequence of the prompt and excepted answer should be in same order.</div> 50 </td> 51 </tr> 52 <tr> 53 <td colspan="1"> 54 <div class="ansibleOptionAnchor" id="parameter-"></div> 55 <b>check_all</b> 56 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> 57 <div style="font-size: small"> 58 <span style="color: purple">boolean</span> 59 </div> 60 </td> 61 <td> 62 <ul style="margin: 0; padding: 0"><b>Choices:</b> 63 <li><div style="color: blue"><b>no</b> ←</div></li> 64 <li>yes</li> 65 </ul> 66 </td> 67 <td> 68 <div>By default if any one of the prompts mentioned in <code>prompt</code> option is matched it won't check for other prompts. This boolean flag, that when set to <em>True</em> will check for all the prompts mentioned in <code>prompt</code> option in the given order. If the option is set to <em>True</em> all the prompts should be received from remote host if not it will result in timeout.</div> 69 </td> 70 </tr> 71 <tr> 72 <td colspan="1"> 73 <div class="ansibleOptionAnchor" id="parameter-"></div> 74 <b>command</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 / <span style="color: red">required</span> 79 </div> 80 </td> 81 <td> 82 </td> 83 <td> 84 <div>The command to send to the remote network device. The resulting output from the command is returned, unless <em>sendonly</em> is set.</div> 85 </td> 86 </tr> 87 <tr> 88 <td colspan="1"> 89 <div class="ansibleOptionAnchor" id="parameter-"></div> 90 <b>newline</b> 91 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> 92 <div style="font-size: small"> 93 <span style="color: purple">boolean</span> 94 </div> 95 </td> 96 <td> 97 <ul style="margin: 0; padding: 0"><b>Choices:</b> 98 <li>no</li> 99 <li><div style="color: blue"><b>yes</b> ←</div></li> 100 </ul> 101 </td> 102 <td> 103 <div>The boolean value, that when set to false will send <em>answer</em> to the device without a trailing newline.</div> 104 </td> 105 </tr> 106 <tr> 107 <td colspan="1"> 108 <div class="ansibleOptionAnchor" id="parameter-"></div> 109 <b>prompt</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>A single regex pattern or a sequence of patterns to evaluate the expected prompt from <em>command</em>.</div> 120 </td> 121 </tr> 122 <tr> 123 <td colspan="1"> 124 <div class="ansibleOptionAnchor" id="parameter-"></div> 125 <b>sendonly</b> 126 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a> 127 <div style="font-size: small"> 128 <span style="color: purple">boolean</span> 129 </div> 130 </td> 131 <td> 132 <ul style="margin: 0; padding: 0"><b>Choices:</b> 133 <li><div style="color: blue"><b>no</b> ←</div></li> 134 <li>yes</li> 135 </ul> 136 </td> 137 <td> 138 <div>The boolean value, that when set to true will send <em>command</em> to the device but not wait for a result.</div> 139 </td> 140 </tr> 141 </table> 142 <br/> 143 144 145Notes 146----- 147 148.. note:: 149 - This module is supported on ``ansible_network_os`` network platforms. See the :ref:`Network Platform Options <platform_options>` for details. 150 151 152 153Examples 154-------- 155 156.. code-block:: yaml 157 158 - name: run show version on remote devices 159 ansible.netcommon.cli_command: 160 command: show version 161 162 - name: run command with json formatted output 163 ansible.netcommon.cli_command: 164 command: show version | json 165 166 - name: run command expecting user confirmation 167 ansible.netcommon.cli_command: 168 command: commit replace 169 prompt: This commit will replace or remove the entire running configuration 170 answer: yes 171 172 - name: run command expecting user confirmation 173 ansible.netcommon.cli_command: 174 command: show interface summary 175 prompt: Press any key to continue 176 answer: y 177 newline: false 178 179 - name: run config mode command and handle prompt/answer 180 ansible.netcommon.cli_command: 181 command: '{{ item }}' 182 prompt: 183 - Exit with uncommitted changes 184 answer: y 185 loop: 186 - configure 187 - set system syslog file test any any 188 - exit 189 190 - name: multiple prompt, multiple answer (mandatory check for all prompts) 191 ansible.netcommon.cli_command: 192 command: copy sftp sftp://user@host//user/test.img 193 check_all: true 194 prompt: 195 - Confirm download operation 196 - Password 197 - Do you want to change that to the standby image 198 answer: 199 - y 200 - <password> 201 - y 202 203 204 205Return Values 206------------- 207Common 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: 208 209.. raw:: html 210 211 <table border=0 cellpadding=0 class="documentation-table"> 212 <tr> 213 <th colspan="1">Key</th> 214 <th>Returned</th> 215 <th width="100%">Description</th> 216 </tr> 217 <tr> 218 <td colspan="1"> 219 <div class="ansibleOptionAnchor" id="return-"></div> 220 <b>json</b> 221 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> 222 <div style="font-size: small"> 223 <span style="color: purple">dictionary</span> 224 </div> 225 </td> 226 <td>when the device response is valid JSON</td> 227 <td> 228 <div>A dictionary representing a JSON-formatted response</div> 229 <br/> 230 <div style="font-size: smaller"><b>Sample:</b></div> 231 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">{ 232 "architecture": "i386", 233 "bootupTimestamp": 1532649700.56, 234 "modelName": "vEOS", 235 "version": "4.15.9M" 236 [...] 237 }</div> 238 </td> 239 </tr> 240 <tr> 241 <td colspan="1"> 242 <div class="ansibleOptionAnchor" id="return-"></div> 243 <b>stdout</b> 244 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a> 245 <div style="font-size: small"> 246 <span style="color: purple">string</span> 247 </div> 248 </td> 249 <td>when sendonly is false</td> 250 <td> 251 <div>The response from the command</div> 252 <br/> 253 <div style="font-size: smaller"><b>Sample:</b></div> 254 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">Version: VyOS 1.1.7[...]</div> 255 </td> 256 </tr> 257 </table> 258 <br/><br/> 259 260 261Status 262------ 263 264 265Authors 266~~~~~~~ 267 268- Nathaniel Case (@Qalthos) 269