Ansible Juniper CLI命令.超时错误? [英] Ansible, Juniper CLI commands. Timeout Error?

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

问题描述

我正在尝试将我在Python中制作的自动化脚本转移到ansible(公司要求),而我以前从未使用过ansible.我已经尝试过"wait_for:",但是我也没有使它起作用.在脚本中,我可以设置dev.timeout = None或任何我需要的值.我发现很难弄清楚在哪里可以做到这一点.我尝试在"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的Ansible模块(junos_cli)不支持超时.为此,我进入了:

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 Juniper CLI命令.超时错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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