首页 文章

在cisco 3850上执行“show conf”时,ansible ios_command超时

提问于
浏览
-1

我有一个简单的ansible playbook,可以在大多数ios设备上正常工作 . 当我执行“show conf”时,我的一些3850交换机出现故障,看起来像是超时 . 如何使用ios_command模块(也可能是ios_config)为命令完成指定更长的非默认超时?

有用的细节:

剧本:

---
- hosts: ios_devices
  gather_facts: no
  connection: local
  tasks:
  - name: OBTAIN LOGIN CREDENTIALS
    include_vars: secrets.yaml

  - name: DEFINE PROVIDER
    set_fact:
      provider:
        host: "{{ inventory_hostname }}"
        username: "{{ creds['username'] }}"
        password: "{{ creds['password'] }}"

  - name: LIST NAME SERVERS
    ios_command:
      provider: "{{ provider }}"
      commands: "show run | inc name-server"
    register: dns_servers

  - debug: var=dns_servers.stdout_lines

成功运行:

$ ansible-playbook listnameserver.yaml -i inventory / onehost PLAY [ios_devices] ********************************* ************************************************** ******************************任务[获得登录证书] ************** ************************************************** ************************确定:[iosdevice1.example.com]任务[定义提供商] ************************************************** ************************************************** ********* ok:[iosdevice1.example.com]任务[列表名称服务器] ************************** ************************************************** 好的:[iosdevice1.example.com] TASK [debug] ****** ************************************************** ************************************************** ************* ok:[iosdevice1.example.com] => {“dns_servers.stdout_lines”:[[“ip name-server 10.1.1.166”,“ip name-server 10.1 . 1.168“]]}玩回忆 *** ************************************************** ************************* iosdevice1.example.com:ok = 4 changed = 0 unreachable = 0 failed = 0

运行不成功:

$ ansible-playbook listnameserver.yaml -i inventory / onehost PLAY [ios_devices] ********************************* ************************************************** ******************************任务[获得登录证书] ************** ************************************************** ************************************确定:[iosdevice2.example.com]任务[定义提供商] ************************************************** ************************************************** ********* ok:[iosdevice2.example.com]任务[列表名称服务器] ************************** ************************************************** *******************************致命:[iosdevice2.example.com]:失败了! => {“已更改”:false,“msg”:“超时尝试发送命令:show run | inc name-server”,“rc”:1}重试,使用: - limit @ / home / sample / ansible -playbooks / listnameserver.retry PLAY RECAP ****************************************** ************************************************** ***************************** iosdevice2.example.com:ok = 2 changed = 0 unreachable = 0 failed = 1

2 回答

  • 0

    如果请求花费的时间超过此ios_command将失败,则默认超时为10秒 .

    您可以将超时添加为提供程序变量中的键,如下所示:

    - name: DEFINE PROVIDER
      set_fact:
        provider:
          host: "{{ inventory_hostname }}"
          username: "{{ creds['username'] }}"
          password: "{{ creds['password'] }}"
          timeout: 30
    
  • 0

    如果你已经在提供者中获得了超时值,那么只能更新变量中的那个键 .

    - name: Update existing provider timeout key
      set_fact:
         provider: "{{ provider | combine( {'timeout': '180'} ) }}"
    

相关问题