cisco.ios.ios_hostname module – Resource module to configure hostname.
Note
This module is part of the cisco.ios collection (version 2.8.1).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install cisco.ios
.
To use it in a playbook, specify: cisco.ios.ios_hostname
.
New in version 2.7.0: of cisco.ios
Parameters
Parameter |
Comments |
---|---|
A dictionary of hostname options |
|
set hostname for IOS |
|
This option is used only with state parsed. The value of this option should be the output received from the IOS device by executing the command show running-config | section ^hostname. The state parsed reads the configuration from |
|
The state the configuration should be left in The states rendered, gathered and parsed does not perform any change on the device. The state rendered will transform the configuration in The states merged, replaced and overridden have identical behaviour for this module. The state gathered 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 gathered key within the result. The state parsed reads the configuration from Choices:
|
Examples
# Using state: merged
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Merged play:
# ------------
- name: Apply the provided configuration
cisco.ios.ios_hostname:
config:
hostname: Router1
state: merged
# Commands Fired:
# ---------------
# "commands": [
# "hostname Router1",
# ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname Router1
# Using state: deleted
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Deleted play:
# -------------
- name: Remove all existing configuration
cisco.ios.ios_hostname:
state: deleted
# Commands Fired:
# ---------------
# "commands": [
# "no hostname RouterTest",
# ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Using state: overridden
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname Router
# Overridden play:
# ----------------
- name: Override commands with provided configuration
cisco.ios.ios_hostname:
config:
hostname: RouterTest
state: overridden
# Commands Fired:
# ---------------
# "commands": [
# "hostname RouterTest",
# ],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Using state: replaced
# Before state:
# -------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Replaced play:
# --------------
- name: Replace commands with provided configuration
cisco.ios.ios_hostname:
config:
hostname: RouterTest
state: replaced
# Commands Fired:
# ---------------
# "commands": [],
# After state:
# ------------
# router-ios#show running-config | section ^hostname
# hostname RouterTest
# Using state: gathered
# Before state:
# -------------
#router-ios#show running-config | section ^hostname
# hostname RouterTest
# Gathered play:
# --------------
- name: Gather listed hostname config
cisco.ios.ios_hostname:
state: gathered
# Module Execution Result:
# ------------------------
# "gathered": {
# "hostname": "RouterTest"
# },
# Using state: rendered
# Rendered play:
# --------------
- name: Render the commands for provided configuration
cisco.ios.ios_hostname:
config:
hostname: RouterTest
state: rendered
# Module Execution Result:
# ------------------------
# "rendered": [
# "hostname RouterTest",
# ]
# Using state: parsed
# File: parsed.cfg
# ----------------
# hostname RouterTest
# Parsed play:
# ------------
- name: Parse the provided configuration with the existing running configuration
cisco.ios.ios_hostname:
running_config: "{{ lookup('file', 'parsed.cfg') }}"
state: parsed
# Module Execution Result:
# ------------------------
# "parsed": {
# "hostname": "RouterTest"
# }
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The resulting configuration after module execution. Returned: when changed Sample: “This output will always be in the same format as the module argspec.\n” |
|
The configuration prior to the module execution. Returned: when state is Sample: “This output will always be in the same format as the module argspec.\n” |
|
The set of commands pushed to the remote device. Returned: when state is Sample: [“hostname Router1”] |
|
Facts about the network resource gathered from the remote device as structured data. Returned: when state is Sample: “This output will always be in the same format as the module argspec.\n” |
|
The device native config provided in running_config option parsed into structured data as per module argspec. Returned: when state is Sample: “This output will always be in the same format as the module argspec.\n” |
|
The provided configuration in the task rendered in device-native format (offline). Returned: when state is Sample: [“hostname Switch1”] |
Authors
Sagar Paul (@KB-perByte)