Ansible、瞻博网络 CLI 命令.超时错误? [英] Ansible, Juniper CLI commands. Timeout Error?

查看:22
本文介绍了Ansible、瞻博网络 CLI 命令.超时错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我用 Python 制作的自动化脚本传输到 ansible(公司请求),而且我以前从未使用过 ansible.我试过wait_for:",但我也没有让它起作用.在脚本中,我可以设置 dev.timeout=None 或任何我需要的.我发现很难弄清楚我在哪里可以用 ansible 做到这一点.我尝试在ansible.cfg"文件中设置超时.但这不起作用.我可以执行简单的命令,例如:

I am trying to transfer an automation script I made in Python, to ansible (company request), and I have NEVER worked with ansible before. I have tried the "wait_for:", but I have not gotten that to work either. In the script, I could set dev.timeout=None or whatever I needed. I am finding it hard to figure out where I can do this in ansible. I have tried setting the timeout in the "ansible.cfg" file. But that doesnt work. I can do simple commands, like:

cli="显示版本",或cli="显示系统固件".

cli="show version", or cli="show system firmware".

以下是我的剧本:

    - hosts: local
  roles:
  - Juniper.junos
  connection: local
  gather_facts: no

  tasks:
  - junos_cli:
      host={{ inventory_hostname }}
      user=root
      passwd=Hardware1
      cli="request system snapshot slice alternate"
      dest="{{ inventory_hostname }}.txt"

运行后,大约 120 秒后,我收到以下错误:

After I run that, around 120 seconds later, I get the following error:

fatal: [192.168.2.254]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py:652: RuntimeWarning: CLI command is for debug use only!\n  warnings.warn(\"CLI command is for debug use only!\", RuntimeWarning)\nTraceback (most recent call last):\n  File \"/home/pkb/.ansible/tmp/ansible-tmp-1457428640.58-63826456311723/junos_cli\", line 2140, in <module>\n    main()\n  File \"/home/pkb/.ansible/tmp/ansible-tmp-1457428640.58-63826456311723/junos_cli\", line 177, in main\n    dev.close()\n  File \"/usr/local/lib/python2.7/dist-packages/jnpr/junos/device.py\", line 504, in close\n    self._conn.close_session()\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 158, in wrapper\n    return self.execute(op_cls, *args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/manager.py\", line 228, in execute\n    raise_mode=self._raise_mode).request(*args, **kwds)\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/session.py\", line 28, in request\n    return self._request(new_ele(\"close-session\"))\n  File \"/usr/local/lib/python2.7/dist-packages/ncclient/operations/rpc.py\", line 342, in _request\n    raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')\nncclient.operations.errors.TimeoutExpiredError: ncclient timed out while waiting for an rpc reply.\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}

我认为是超时,我可能是错的.但让我头疼的是,这么简单的任务却让我望而却步.

I think it is the timeout, I could be wrong. But it is doing my head in that such a simple task is eluding me.

推荐答案

好的,我设法解决了这个问题.

Okay, I managed to fix the problem.

执行 CLI (junos_cli) 的 Ansible 模块不支持超时.我因此进入:

The module for Ansible that does the CLI (junos_cli) doesn't support timeout. I therefor went in to:

/etc/ansible/roles/Juniper.junos/library/junos_cli

下面一行:

dev = Device(args['host'], user=args['user'], password=args['passwd'],
                     port=args['port'], gather_facts=False).open()

我补充说:

dev.timeout=None

这将计时器设置为无穷大,因此在执行请求系统快照切片替代"时我有时间进行格式化.

This sets the timer to infinity, so I have time for the formatting when doing "request system snapshot slice alternate".

希望这可以帮助其他人通过 ansible 自动化使用 junos cli 做一些事情.

Hope this helps anyone else doing something with the junos cli through ansible automation.

这篇关于Ansible、瞻博网络 CLI 命令.超时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆