首先,确保已经成功更新了路由器主机名。可以使用模块 'ios_command'检查该主机名是否已成功更改。
之后,考虑重载路由器以应用新的主机名。可以使用模块 'ios_command'执行重载路由器的命令。
示例代码:
name: Update the hostname of the router ios_config: lines: - hostname R3 register: hostname_result
name: Check if hostname update was successful ios_command: commands: - show running-config | include hostname register: hostname_check_result
name: Reload the router to apply the new hostname ios_command: commands: - reload - yes
注意:执行 reload 命令会使路由器重新启动,需要谨慎操作。