Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nxos action plugin for nxos_install_os #53768

Merged

Conversation

mikewiebe
Copy link
Contributor

@mikewiebe mikewiebe commented Mar 13, 2019

SUMMARY

Fixes #52206

  • Fix checks the connection type before attempting to determine the current values for PERSISTENT_COMMAND_TIMEOUT and PERSISTENT_CONNECT_TIMEOUT
  • Adds additional debug information to display the TIMEOUT values on failure.
  • Adds current timer values to the verbose -vvvv output.

NOTE: For connection: local (cli) or (nxapi) setting vars in the playbook task or passing via the -e argument have no effect. Setting environment variables or setting ansible.cfg however, do work.

I am open to suggestions about how we get playbook task vars to take effect for connection: local (cli) or (nxapi).

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

nxos_install_os

ADDITIONAL INFORMATION

The following tests were run to validate this fix.

CONNECTION: network_cli

  • TESTCASE: Timers NOT set
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin network_cli
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/bcc36897f8
<n9k> PERSISTENT_COMMAND_TIMEOUT is 30
<n9k> PERSISTENT_CONNECT_TIMEOUT is 30
  • TESTCASE: Timers set using ENV vars
(py2-ansible) $env | grep ANSIBLE_PERS
ANSIBLE_PERSISTENT_COMMAND_TIMEOUT=600
ANSIBLE_PERSISTENT_CONNECT_TIMEOUT=600
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin network_cli
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/4ac6359588
<n9k> PERSISTENT_COMMAND_TIMEOUT is 600
<n9k> PERSISTENT_CONNECT_TIMEOUT is 600
  • TESTCASE: Timers set using ansible.cfg
$cat /etc/ansible/ansible.cfg 
[persistent_connection]
connect_timeout=800
command_timeout=800
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin network_cli
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/c700b6b398
<n9k> PERSISTENT_COMMAND_TIMEOUT is 800
<n9k> PERSISTENT_CONNECT_TIMEOUT is 800
  • TESTCASE: Timers set using vars in playbook task
- name: "Install OS image {{ si }}"
  check_mode: "{{ checkmode }}"
  nxos_install_os:
    system_image_file: "{{ si }}"
    issu: "{{ issu }}"
    provider: "{{ connection }}"
  vars:
    ansible_command_timeout: 700
    ansible_connect_timeout: 700
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin network_cli
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/e8335c6594
<n9k> PERSISTENT_COMMAND_TIMEOUT is 700
<n9k> PERSISTENT_CONNECT_TIMEOUT is 700
  • TESTCASE: Timers set by passing them in to ansible-playbook using -e option

ansible-playbook nxos.yaml -e "ansible_command_timeout=1000 ansible_connect_timeout=900"

TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin network_cli
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/01ee8deb61
<n9k> PERSISTENT_COMMAND_TIMEOUT is 1000
<n9k> PERSISTENT_CONNECT_TIMEOUT is 900

CONNECTION: httpapi

  • TESTCASE: Timers NOT set
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin httpapi
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/11c4d12331
<n9k> PERSISTENT_COMMAND_TIMEOUT is 30
<n9k> PERSISTENT_CONNECT_TIMEOUT is 30
  • TESTCASE: Timers set using ENV vars
(py2-ansible) $env | grep ANSIBLE_PERS
ANSIBLE_PERSISTENT_COMMAND_TIMEOUT=600
ANSIBLE_PERSISTENT_CONNECT_TIMEOUT=600
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin httpapi
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/0606e69189
<n9k> PERSISTENT_COMMAND_TIMEOUT is 600
<n9k> PERSISTENT_CONNECT_TIMEOUT is 600
  • TESTCASE: Timers set using ansible.cfg
$cat /etc/ansible/ansible.cfg 
[persistent_connection]
connect_timeout=800
command_timeout=800
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin httpapi
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/9012e40de0
<n9k> PERSISTENT_COMMAND_TIMEOUT is 800
<n9k> PERSISTENT_CONNECT_TIMEOUT is 800
  • TESTCASE: Timers set using vars in playbook task
- name: "Install OS image {{ si }}"
  check_mode: "{{ checkmode }}"
  nxos_install_os:
    system_image_file: "{{ si }}"
    issu: "{{ issu }}"
    provider: "{{ connection }}"
  vars:
    ansible_command_timeout: 700
    ansible_connect_timeout: 700
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin httpapi
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/b9d0d42858
<n9k> PERSISTENT_COMMAND_TIMEOUT is 700
<n9k> PERSISTENT_CONNECT_TIMEOUT is 700
  • TESTCASE: Timers set by passing them in to ansible-playbook using -e option

ansible-playbook nxos.yaml -e "ansible_command_timeout=1000 ansible_connect_timeout=900"

TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> attempting to start connection
<n9k> using connection plugin httpapi
<n9k> found existing local domain socket, using it!
<n9k> updating play_context for connection
<n9k> 
<n9k> local domain socket path is /Users/mwiebe/.ansible/pc/8bf7088d5a
<n9k> PERSISTENT_COMMAND_TIMEOUT is 1000
<n9k> PERSISTENT_CONNECT_TIMEOUT is 900

CONNECTION: local (cli)

  • TESTCASE: Timers NOT set
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> PERSISTENT_COMMAND_TIMEOUT is 30
<n9k> PERSISTENT_CONNECT_TIMEOUT is 30
  • TESTCASE: Timers set using ENV vars
(py2-ansible) $env | grep ANSIBLE_PERS
ANSIBLE_PERSISTENT_COMMAND_TIMEOUT=600
ANSIBLE_PERSISTENT_CONNECT_TIMEOUT=600
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> PERSISTENT_COMMAND_TIMEOUT is 600
<n9k> PERSISTENT_CONNECT_TIMEOUT is 600
  • TESTCASE: Timers set using ansible.cfg
$cat /etc/ansible/ansible.cfg 
[persistent_connection]
connect_timeout=800
command_timeout=800
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> PERSISTENT_COMMAND_TIMEOUT is 800
<n9k> PERSISTENT_CONNECT_TIMEOUT is 800
  • TESTCASE: Timers set using vars in playbook task - FAILED
- name: "Install OS image {{ si }}"
  check_mode: "{{ checkmode }}"
  nxos_install_os:
    system_image_file: "{{ si }}"
    issu: "{{ issu }}"
    provider: "{{ connection }}"
  vars:
    ansible_command_timeout: 700
    ansible_connect_timeout: 700
TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> PERSISTENT_COMMAND_TIMEOUT is 30
<n9k> PERSISTENT_CONNECT_TIMEOUT is 30
  • TESTCASE: Timers set by passing them in to ansible-playbook using -e option - FAILED

ansible-playbook nxos.yaml -e "ansible_command_timeout=1000 ansible_connect_timeout=900"

TASK [nxos_install_os : Install OS image nxos.7.0.3.I7.4.bin] ***************************************************************************************************************************************************************
task path: /Users/mwiebe/Projects/nxos_ansible/fix_ansible/test/integration/targets/nxos_install_os/tasks/upgrade/install_system.yaml:2
<n9k> PERSISTENT_COMMAND_TIMEOUT is 30
<n9k> PERSISTENT_CONNECT_TIMEOUT is 30

CONNECTION: local (nxapi)

  • Same results as CONNECTION: local (cli)

@ansibot
Copy link
Contributor

ansibot commented Mar 13, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cisco Cisco technologies core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. networking Network category nxos Cisco NXOS community support:network This issue/PR relates to code supported by the Ansible Network Team. labels Mar 13, 2019
@trishnaguha trishnaguha self-assigned this Mar 14, 2019
@trishnaguha trishnaguha removed the needs_triage Needs a first human triage before being processed. label Mar 14, 2019
connection = self._connection
if connection.get_option('persistent_command_timeout') < 600 or connection.get_option('persistent_connect_timeout') < 600:
if connection.transport == 'local':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikewiebe Can you update the module docs which states, if someone wants to set the timeouts as config task variable network_cli/httpapi connection plugin is required. local only supports these timeout values with ansible.cfg or env var.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can do that.

@ansibot
Copy link
Contributor

ansibot commented Mar 14, 2019

@ansibot ansibot added the module This issue/PR relates to a module. label Mar 14, 2019
@mikewiebe
Copy link
Contributor Author

@trishnaguha Can we go ahead and merge this?

Copy link
Member

@trishnaguha trishnaguha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mikewiebe

@trishnaguha trishnaguha merged commit 4c2a3bf into ansible:devel Mar 18, 2019
@trishnaguha trishnaguha added this to Needs Triage in Networking via automation Mar 18, 2019
trishnaguha pushed a commit to trishnaguha/ansible that referenced this pull request Apr 1, 2019
* Fix nxos action plugin for nxos_install_os

* Update module docs

(cherry picked from commit 4c2a3bf)
abadger pushed a commit that referenced this pull request Apr 4, 2019
* Fix nxos action plugin for nxos_install_os

* Update module docs

(cherry picked from commit 4c2a3bf)
@fcam-naveen
Copy link

Which version of Ansible this fix is available?

@fcam-naveen
Copy link

I just copied this file alone, it fails like this

TASK [Install OS on N6k] ***************************************************************************************************************************************************
task path: /Users/nsekhar/Work/virtual-env/myansible/cisco/nxos_upgrade.yaml:321
The full traceback is:
Traceback (most recent call last):
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 106, in run
item_results = self._run_loop(items)
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 343, in _run_loop
res = self._execute(variables=task_vars)
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 563, in _execute
self._handler = self._get_action_handler(connection=self._connection, templar=templar)
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 929, in _get_action_handler
shared_loader_obj=self._shared_loader_obj,
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/plugins/loader.py", line 378, in get
self._module_cache[path] = self._load_module_source(name, path)
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/plugins/loader.py", line 357, in _load_module_source
module = imp.load_source(full_name, path, module_file)
File "/Users/nsekhar/Work/virtual-env/myansible/lib/python2.7/site-packages/ansible/plugins/action/nxos.py", line 29, in
from ansible.plugins.action.network import ActionModule as ActionNetworkModule
ImportError: No module named network

fatal: [10.9.8.115]: FAILED! => {
"msg": "Unexpected failure during module execution.",
"stdout": ""

@trishnaguha
Copy link
Member

@fcam-naveen It will be available in 2.7.11 version, not released yet.
If you want to test, please check stable-2.7 branch.
To test stable-2.7, follow these steps:

git clone https://github.com/ansible/ansible.git --single-branch --branch stable-2.7
cd ansible
source hacking/env-setup

@Sulemanaaa
Copy link

@trishnaguha so there is no way to get this working on 2.7.10? i have to upgrade 60 + switches and would love to automate this. I am getting the same error as in this post and looking for a fix :)

@trishnaguha
Copy link
Member

trishnaguha commented Apr 16, 2019

@Sulemanaaa We don't backport fixes to the version that is already released. For a stable release you will have to wait for 2.7.11 to release. Your patience will be much appreciated :-).

However you can still pull stable-2.7 branch from github locally and use it until 2.7.11 is released to get this fix working.

git clone -b stable-2.7 https://github.com/ansible/ansible.git
cd ansible
source hacking/env-setup

ansible --version will now point to ansible 2.7.10.post0

This will enable stable-2.7 version of ansible on your local environment for that specific terminal session.
To disable it, just exit that terminal session.

Hope this helps!

@Sulemanaaa
Copy link

Thank you @trishnaguha tried the steps and getting:

self.local_index = Environment(self.shadow_path + sys.path)
error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: Setup script exited with error: [Errno 63] File name too long: '/var/folders/ch/bvvgyn4d41b5psz7vrm24dp40000gn/T/easy_install-orJxko/pip-19.0.3/temp/easy_install-ufCnMK/pip-19.0.3/temp/easy_install-RKPkCi/pip-19.0.3/temp/easy_install-L5X2JN/pip-19.0.3/temp/easy_install-bOrH0j/pip-19.0.3/temp/easy_install-c8S4u9/pip-19.0.3/temp/easy_install-SiXEPb/pip-19.0.3/temp/easy_install-vAUktn/pip-19.0.3/temp/easy_install-YA4lpp/pip-19.0.3/temp/easy_install-XyfSO8/pip-19.0.3/temp/easy_install-OT0C5e/pip-19.0.3/temp/easy_install-2jmdk4/pip-19.0.3/temp/easy_install-mjOsQ4/pip-19.0.3/temp/easy_install-hMpUM_/pip-19.0.3/temp/easy_install-v84ciV/pip-19.0.3/temp/easy_install-bKy5of/pip-19.0.3/temp/easy_install-O7ktai/pip-19.0.3/temp/easy_install-U0lwNa/pip-19.0.3/temp/easy_install-0nd1kW/pip-19.0.3/temp/easy_install-DevX3P/pip-19.0.3/temp/easy_install-XH3XaW/pip-19.0.3/temp/easy_install-Ggiqe8/pip-19.0.3/temp/easy_install-aZ0xIn/pip-19.0.3/temp/easy_install-HY0xTP/pip-19.0.3/temp/easy_install-th9_4d/pip-19.0.3/temp/easy_install-aVvGoL/pip-19.0.3/docs/html/development/configuration.rst'

Setting up Ansible to run out of checkout...

PATH=/Users/sushahid/ansible/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Users/sushahid/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/bin/jamf:/usr/local/git/bin
PYTHONPATH=/Users/sushahid/ansible/lib
MANPATH=/Users/sushahid/ansible/docs/man

Remember, you may wish to specify your host file with -i

Done!

You have mail in /var/mail/sushahid
SUSHAHID-M-91WP:ansible sushahid$
SUSHAHID-M-91WP:ansible sushahid$
SUSHAHID-M-91WP:ansible sushahid$ ansible --version
Traceback (most recent call last):
File "/Users/sushahid/ansible/bin/ansible", line 67, in
import ansible.constants as C
File "/Users/sushahid/ansible/lib/ansible/constants.py", line 11, in
from jinja2 import Template
ImportError: No module named jinja2
SUSHAHID-M-91WP:ansible sushahid$

@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cisco Cisco technologies core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. networking Network category nxos Cisco NXOS community support:network This issue/PR relates to code supported by the Ansible Network Team.
Projects
No open projects
Networking
  
Needs Triage
Development

Successfully merging this pull request may close these issues.

nxos_install_os not recognizing persistent_command_timeout when defined in ansible.cfg (ansible 2.7.7)
5 participants