Debian Codegraph @

ansible_collections/cisco/ios/docs/cisco.ios.ios_hostname_module.rst

raw
1 .. _cisco.ios.ios_hostname_module:
2
3
4 **********************
5 cisco.ios.ios_hostname
6 **********************
7
8 **Resource module to configure hostname.**
9
10
11 Version added: 2.7.0
12
13 .. contents::
14 :local:
15 :depth: 1
16
17
18 Synopsis
19 --------
20 - This module provides declarative management of hostname on Cisco IOS devices.
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="2">Parameter</th>
33 <th>Choices/<font color="blue">Defaults</font></th>
34 <th width="100%">Comments</th>
35 </tr>
36 <tr>
37 <td colspan="2">
38 <div class="ansibleOptionAnchor" id="parameter-"></div>
39 <b>config</b>
40 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
41 <div style="font-size: small">
42 <span style="color: purple">dictionary</span>
43 </div>
44 </td>
45 <td>
46 </td>
47 <td>
48 <div>A dictionary of hostname options</div>
49 </td>
50 </tr>
51 <tr>
52 <td class="elbow-placeholder"></td>
53 <td colspan="1">
54 <div class="ansibleOptionAnchor" id="parameter-"></div>
55 <b>hostname</b>
56 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
57 <div style="font-size: small">
58 <span style="color: purple">string</span>
59 </div>
60 </td>
61 <td>
62 </td>
63 <td>
64 <div>set hostname for IOS</div>
65 </td>
66 </tr>
67
68 <tr>
69 <td colspan="2">
70 <div class="ansibleOptionAnchor" id="parameter-"></div>
71 <b>running_config</b>
72 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
73 <div style="font-size: small">
74 <span style="color: purple">string</span>
75 </div>
76 </td>
77 <td>
78 </td>
79 <td>
80 <div>This option is used only with state <em>parsed</em>.</div>
81 <div>The value of this option should be the output received from the IOS device by executing the command <b>show running-config | section ^hostname</b>.</div>
82 <div>The state <em>parsed</em> reads the configuration from <code>running_config</code> option and transforms it into Ansible structured data as per the resource module&#x27;s argspec and the value is then returned in the <em>parsed</em> key within the result.</div>
83 </td>
84 </tr>
85 <tr>
86 <td colspan="2">
87 <div class="ansibleOptionAnchor" id="parameter-"></div>
88 <b>state</b>
89 <a class="ansibleOptionLink" href="#parameter-" title="Permalink to this option"></a>
90 <div style="font-size: small">
91 <span style="color: purple">string</span>
92 </div>
93 </td>
94 <td>
95 <ul style="margin: 0; padding: 0"><b>Choices:</b>
96 <li><div style="color: blue"><b>merged</b>&nbsp;&larr;</div></li>
97 <li>replaced</li>
98 <li>overridden</li>
99 <li>deleted</li>
100 <li>rendered</li>
101 <li>gathered</li>
102 <li>parsed</li>
103 </ul>
104 </td>
105 <td>
106 <div>The state the configuration should be left in</div>
107 <div>The states <em>rendered</em>, <em>gathered</em> and <em>parsed</em> does not perform any change on the device.</div>
108 <div>The state <em>rendered</em> will transform the configuration in <code>config</code> option to platform specific CLI commands which will be returned in the <em>rendered</em> key within the result. For state <em>rendered</em> active connection to remote host is not required.</div>
109 <div>The states <em>merged</em>, <em>replaced</em> and <em>overridden</em> have identical behaviour for this module.</div>
110 <div>The state <em>gathered</em> will fetch the running configuration from device and transform it into structured data in the format as per the resource module argspec and the value is returned in the <em>gathered</em> key within the result.</div>
111 <div>The state <em>parsed</em> reads the configuration from <code>running_config</code> option and transforms it into JSON format as per the resource module parameters and the value is returned in the <em>parsed</em> key within the result. The value of <code>running_config</code> option should be the same format as the output of command <em>show running-config | section ^hostname</em> executed on device. For state <em>parsed</em> active connection to remote host is not required.</div>
112 </td>
113 </tr>
114 </table>
115 <br/>
116
117
118 Notes
119 -----
120
121 .. note::
122 - Tested against Cisco IOSXE Version 17.3 on CML.
123 - This module works with connection ``network_cli``.
124
125
126
127 Examples
128 --------
129
130 .. code-block:: yaml
131
132 # Using state: merged
133
134 # Before state:
135 # -------------
136
137 # router-ios#show running-config | section ^hostname
138 # hostname Router
139
140 # Merged play:
141 # ------------
142
143 - name: Apply the provided configuration
144 cisco.ios.ios_hostname:
145 config:
146 hostname: Router1
147 state: merged
148
149 # Commands Fired:
150 # ---------------
151
152 # "commands": [
153 # "hostname Router1",
154 # ],
155
156 # After state:
157 # ------------
158
159 # router-ios#show running-config | section ^hostname
160 # hostname Router1
161
162 # Using state: deleted
163
164 # Before state:
165 # -------------
166
167 # router-ios#show running-config | section ^hostname
168 # hostname RouterTest
169
170 # Deleted play:
171 # -------------
172
173 - name: Remove all existing configuration
174 cisco.ios.ios_hostname:
175 state: deleted
176
177 # Commands Fired:
178 # ---------------
179
180 # "commands": [
181 # "no hostname RouterTest",
182 # ],
183
184 # After state:
185 # ------------
186
187 # router-ios#show running-config | section ^hostname
188 # hostname Router
189
190 # Using state: overridden
191
192 # Before state:
193 # -------------
194
195 # router-ios#show running-config | section ^hostname
196 # hostname Router
197
198 # Overridden play:
199 # ----------------
200
201 - name: Override commands with provided configuration
202 cisco.ios.ios_hostname:
203 config:
204 hostname: RouterTest
205 state: overridden
206
207 # Commands Fired:
208 # ---------------
209 # "commands": [
210 # "hostname RouterTest",
211 # ],
212
213 # After state:
214 # ------------
215
216 # router-ios#show running-config | section ^hostname
217 # hostname RouterTest
218
219 # Using state: replaced
220
221 # Before state:
222 # -------------
223
224 # router-ios#show running-config | section ^hostname
225 # hostname RouterTest
226
227 # Replaced play:
228 # --------------
229
230 - name: Replace commands with provided configuration
231 cisco.ios.ios_hostname:
232 config:
233 hostname: RouterTest
234 state: replaced
235
236 # Commands Fired:
237 # ---------------
238
239 # "commands": [],
240
241 # After state:
242 # ------------
243
244 # router-ios#show running-config | section ^hostname
245 # hostname RouterTest
246
247 # Using state: gathered
248
249 # Before state:
250 # -------------
251
252 # router-ios#show running-config | section ^hostname
253 # hostname RouterTest
254
255 # Gathered play:
256 # --------------
257
258 - name: Gather listed hostname config
259 cisco.ios.ios_hostname:
260 state: gathered
261
262 # Module Execution Result:
263 # ------------------------
264
265 # "gathered": {
266 # "hostname": "RouterTest"
267 # },
268
269 # Using state: rendered
270
271 # Rendered play:
272 # --------------
273
274 - name: Render the commands for provided configuration
275 cisco.ios.ios_hostname:
276 config:
277 hostname: RouterTest
278 state: rendered
279
280 # Module Execution Result:
281 # ------------------------
282
283 # "rendered": [
284 # "hostname RouterTest",
285 # ]
286
287 # Using state: parsed
288
289 # File: parsed.cfg
290 # ----------------
291
292 # hostname RouterTest
293
294 # Parsed play:
295 # ------------
296
297 - name: Parse the provided configuration with the existing running configuration
298 cisco.ios.ios_hostname:
299 running_config: "{{ lookup('file', 'parsed.cfg') }}"
300 state: parsed
301
302 # Module Execution Result:
303 # ------------------------
304
305 # "parsed": {
306 # "hostname": "RouterTest"
307 # }
308
309
310
311 Return Values
312 -------------
313 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:
314
315 .. raw:: html
316
317 <table border=0 cellpadding=0 class="documentation-table">
318 <tr>
319 <th colspan="1">Key</th>
320 <th>Returned</th>
321 <th width="100%">Description</th>
322 </tr>
323 <tr>
324 <td colspan="1">
325 <div class="ansibleOptionAnchor" id="return-"></div>
326 <b>after</b>
327 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
328 <div style="font-size: small">
329 <span style="color: purple">dictionary</span>
330 </div>
331 </td>
332 <td>when changed</td>
333 <td>
334 <div>The resulting configuration after module execution.</div>
335 <br/>
336 <div style="font-size: smaller"><b>Sample:</b></div>
337 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">This output will always be in the same format as the module argspec.</div>
338 </td>
339 </tr>
340 <tr>
341 <td colspan="1">
342 <div class="ansibleOptionAnchor" id="return-"></div>
343 <b>before</b>
344 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
345 <div style="font-size: small">
346 <span style="color: purple">dictionary</span>
347 </div>
348 </td>
349 <td>when <em>state</em> is <code>merged</code>, <code>replaced</code>, <code>overridden</code>, <code>deleted</code> or <code>purged</code></td>
350 <td>
351 <div>The configuration prior to the module execution.</div>
352 <br/>
353 <div style="font-size: smaller"><b>Sample:</b></div>
354 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">This output will always be in the same format as the module argspec.</div>
355 </td>
356 </tr>
357 <tr>
358 <td colspan="1">
359 <div class="ansibleOptionAnchor" id="return-"></div>
360 <b>commands</b>
361 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
362 <div style="font-size: small">
363 <span style="color: purple">list</span>
364 </div>
365 </td>
366 <td>when <em>state</em> is <code>merged</code>, <code>replaced</code>, <code>overridden</code>, <code>deleted</code> or <code>purged</code></td>
367 <td>
368 <div>The set of commands pushed to the remote device.</div>
369 <br/>
370 <div style="font-size: smaller"><b>Sample:</b></div>
371 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;hostname Router1&#x27;]</div>
372 </td>
373 </tr>
374 <tr>
375 <td colspan="1">
376 <div class="ansibleOptionAnchor" id="return-"></div>
377 <b>gathered</b>
378 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
379 <div style="font-size: small">
380 <span style="color: purple">list</span>
381 </div>
382 </td>
383 <td>when <em>state</em> is <code>gathered</code></td>
384 <td>
385 <div>Facts about the network resource gathered from the remote device as structured data.</div>
386 <br/>
387 <div style="font-size: smaller"><b>Sample:</b></div>
388 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">This output will always be in the same format as the module argspec.</div>
389 </td>
390 </tr>
391 <tr>
392 <td colspan="1">
393 <div class="ansibleOptionAnchor" id="return-"></div>
394 <b>parsed</b>
395 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
396 <div style="font-size: small">
397 <span style="color: purple">list</span>
398 </div>
399 </td>
400 <td>when <em>state</em> is <code>parsed</code></td>
401 <td>
402 <div>The device native config provided in <em>running_config</em> option parsed into structured data as per module argspec.</div>
403 <br/>
404 <div style="font-size: smaller"><b>Sample:</b></div>
405 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">This output will always be in the same format as the module argspec.</div>
406 </td>
407 </tr>
408 <tr>
409 <td colspan="1">
410 <div class="ansibleOptionAnchor" id="return-"></div>
411 <b>rendered</b>
412 <a class="ansibleOptionLink" href="#return-" title="Permalink to this return value"></a>
413 <div style="font-size: small">
414 <span style="color: purple">list</span>
415 </div>
416 </td>
417 <td>when <em>state</em> is <code>rendered</code></td>
418 <td>
419 <div>The provided configuration in the task rendered in device-native format (offline).</div>
420 <br/>
421 <div style="font-size: smaller"><b>Sample:</b></div>
422 <div style="font-size: smaller; color: blue; word-wrap: break-word; word-break: break-all;">[&#x27;hostname Switch1&#x27;]</div>
423 </td>
424 </tr>
425 </table>
426 <br/><br/>
427
428
429 Status
430 ------
431
432
433 Authors
434 ~~~~~~~
435
436 - Sagar Paul (@KB-perByte)