Ansible, Juniper CLI commands. Timeout Error?

守給你的承諾、 提交于 2020-01-02 09:52:28

问题


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="show version", or cli="show system firmware".

The following is my playbook:

    - 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"

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.


回答1:


Okay, I managed to fix the problem.

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

And below line:

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

I added:

dev.timeout=None

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

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




回答2:


It's suggested to increase the timeout value to some decent number (say 300 sec) which we think should be good for the call, rather than making it infinite.



来源:https://stackoverflow.com/questions/35863701/ansible-juniper-cli-commands-timeout-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!