From 9692394c7dc9c7dabd45ab019149c1d00618d2b2 Mon Sep 17 00:00:00 2001 From: Trishna Guha Date: Mon, 19 Feb 2018 11:22:30 +0530 Subject: [PATCH] Stable 2.5 (#36374) * Set hostname to 'switch' on nxos_system (#36373) Signed-off-by: Trishna Guha (cherry picked from commit eb7f4460c82fc72fe0545e8155e16ec30c7cb93d) * fix nxos_config json pipeline error (#36236) Signed-off-by: Trishna Guha (cherry picked from commit 736d6406c049851d9490a3d60d1da049629f3ceb) --- .../modules/network/nxos/nxos_config.py | 19 +++++++++++++------ .../nxos_system/tests/common/sanity.yaml | 2 +- .../tests/common/set_hostname.yaml | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/network/nxos/nxos_config.py b/lib/ansible/modules/network/nxos/nxos_config.py index 61ccc5036a1..e59887747e8 100644 --- a/lib/ansible/modules/network/nxos/nxos_config.py +++ b/lib/ansible/modules/network/nxos/nxos_config.py @@ -113,9 +113,9 @@ options: the modified lines are pushed to the device in configuration mode. If the replace argument is set to I(block) then the entire command block is pushed to the device in configuration mode if any - line is not correct. I(replace config) is supported on Nexus 9K device. + line is not correct. I(replace config) is supported only on Nexus 9K device. required: false - default: lineo + default: line choices: ['line', 'block', 'config'] force: description: @@ -290,6 +290,7 @@ backup_path: from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.connection import ConnectionError from ansible.module_utils.network.common.config import NetworkConfig, dumps from ansible.module_utils.network.nxos.nxos import get_config, load_config, run_commands from ansible.module_utils.network.nxos.nxos import get_capabilities @@ -390,12 +391,18 @@ def main(): config = None - info = get_capabilities(module).get('device_info', {}) - os_platform = info.get('network_os_platform', '') + try: + info = get_capabilities(module) + api = info.get('network_api', 'nxapi') + device_info = info.get('device_info', {}) + os_platform = device_info.get('network_os_platform', '') + except ConnectionError: + api = '' + os_platform = '' - if module.params['replace'] == 'config': + if api == 'cliconf' and module.params['replace'] == 'config': if '9K' not in os_platform: - module.fail_json(msg='replace: config is supported only for Nexus 9K series switches') + module.fail_json(msg='replace: config is supported only on Nexus 9K series switches') if module.params['replace_src']: if module.params['replace'] != 'config': diff --git a/test/integration/targets/nxos_system/tests/common/sanity.yaml b/test/integration/targets/nxos_system/tests/common/sanity.yaml index af6da7585e9..0b513699e05 100644 --- a/test/integration/targets/nxos_system/tests/common/sanity.yaml +++ b/test/integration/targets/nxos_system/tests/common/sanity.yaml @@ -6,7 +6,7 @@ - block: - name: configure hostname and domain-name nxos_system: &hostname - hostname: "{{ inventory_hostname_short }}" + hostname: switch domain_name: test.example.com provider: "{{ connection }}" diff --git a/test/integration/targets/nxos_system/tests/common/set_hostname.yaml b/test/integration/targets/nxos_system/tests/common/set_hostname.yaml index 12f0e05c636..1521d46bc8b 100644 --- a/test/integration/targets/nxos_system/tests/common/set_hostname.yaml +++ b/test/integration/targets/nxos_system/tests/common/set_hostname.yaml @@ -6,7 +6,7 @@ - block: - name: setup nxos_config: - lines: "hostname {{ inventory_hostname_short }}" + lines: hostname switch match: none provider: "{{ connection }}" @@ -33,7 +33,7 @@ always: - name: teardown nxos_config: - lines: "hostname {{ inventory_hostname_short }}" + lines: hostname switch match: none provider: "{{ connection }}"