cisco / cisco.ios / 8.0.0 / module / ios_hostname Resource module to configure hostname. | "added in version" 2.7.0 of cisco.ios" Authors: Sagar Paul (@KB-perByte)cisco.ios.ios_hostname (8.0.0) — module
Install with ansible-galaxy collection install cisco.ios:==8.0.0
collections: - name: cisco.ios version: 8.0.0
This module provides declarative management of hostname on Cisco IOS devices.
# 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
state: choices: - merged - replaced - overridden - deleted - rendered - gathered - parsed default: merged description: - The state the configuration should be left in - The states I(rendered), I(gathered) and I(parsed) does not perform any change on the device. - The state I(rendered) will transform the configuration in C(config) option to platform specific CLI commands which will be returned in the I(rendered) key within the result. For state I(rendered) active connection to remote host is not required. - The states I(merged), I(replaced) and I(overridden) have identical behaviour for this module. - The state I(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 I(gathered) key within the result. - The state I(parsed) reads the configuration from C(running_config) option and transforms it into JSON format as per the resource module parameters and the value is returned in the I(parsed) key within the result. The value of C(running_config) option should be the same format as the output of command I(show running-config | section ^hostname) executed on device. For state I(parsed) active connection to remote host is not required. type: str config: description: A dictionary of hostname options suboptions: hostname: description: set hostname for IOS type: str type: dict running_config: description: - This option is used only with state I(parsed). - The value of this option should be the output received from the IOS device by executing the command B(show running-config | section ^hostname). - The state I(parsed) reads the configuration from C(running_config) option and transforms it into Ansible structured data as per the resource module's argspec and the value is then returned in the I(parsed) key within the result. type: str
after: description: The resulting configuration after module execution. returned: when changed sample: 'This output will always be in the same format as the module argspec. ' type: dict before: description: The configuration prior to the module execution. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) sample: 'This output will always be in the same format as the module argspec. ' type: dict commands: description: The set of commands pushed to the remote device. returned: when I(state) is C(merged), C(replaced), C(overridden), C(deleted) or C(purged) sample: - hostname Router1 type: list gathered: description: Facts about the network resource gathered from the remote device as structured data. returned: when I(state) is C(gathered) sample: 'This output will always be in the same format as the module argspec. ' type: list parsed: description: The device native config provided in I(running_config) option parsed into structured data as per module argspec. returned: when I(state) is C(parsed) sample: 'This output will always be in the same format as the module argspec. ' type: list rendered: description: The provided configuration in the task rendered in device-native format (offline). returned: when I(state) is C(rendered) sample: - hostname Switch1 type: list