ansible-collections / cisco.ios

Ansible Network Collection for Cisco IOS
GNU General Public License v3.0
293 stars 171 forks source link

cisco.ios.ios_config does not leave config mode on invalid command #374

Closed AliArfan closed 3 years ago

AliArfan commented 3 years ago

Summary

Hi,

I stumbled upon this thread while looking for a solution, and thought it perhaps might be a bug or potential feature request: https://github.com/ansible/ansible/issues/32416. When an invalid command is issued via the cisco.ios.ios_config module the playbook will fail, but the device remain in configuration mode. Desired outcome is that the playbook leaves the configuration mode, so the next run of the playbook does not fail when setting the terminal parameters.

Issue Type

Bug Report

Component Name

cisco.ios.ios_config

Ansible Version

$ ansible --version
ansible 2.10.7
  config file = None
  configured module search path = ['/home/ali/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ali/.cache/pypoetry/virtualenvs/nsansible-playbooks-1psT55Hb-py3.9/lib/python3.9/site-packages/ansible
  executable location = /home/ali/.cache/pypoetry/virtualenvs/nsansible-playbooks-1psT55Hb-py3.9/bin/ansible
  python version = 3.9.4 (default, Apr  9 2021, 01:03:21) [GCC 9.3.0]

Configuration

$ ansible-config dump --only-changed
Empty, no output

OS / Environment

Ubuntu 20.04 (Windows 10 WSL)

Steps to Reproduce

Playbook to reproduce the problem, where invalid configuration is pushed

- name: Validate configuration after push
  hosts: "{{ DEVICE }}"
  gather_facts: no
  connection: network_cli

  tasks:
    - name: Push new configuration
      cisco.ios.ios_config:
          lines:
            vrf definition Test description 'Failingcommand'"

Expected Results

Playbook leaves the configuration mode, so the next run does not fail to set terminal parameters.

Actual Results

Results in the device staying in the configuration mode:

Test-Device(config)#vrf definition Test description 'Failingcommand'"
vrf definition Test description 'Failingcommand'"
                    ^
% Invalid input detected at '^' marker.

Test-Device(config)#
KB-perByte commented 3 years ago

Hi @AliArfan, In any given case the prompt is expected to reset and reach config mode on using the config module which resets the prompt. We are unable to reproduce the issue you reported, at our end. Can you please specify what you mean by 'so the next run does not fail to set terminal parameters' in Expected result? Or help us with an example with its verbose output.

AliArfan commented 3 years ago

Hi,

Thank you for your reply.

We have a playbook which changes the configuration on the device, and the commands are provided trough a variable. We are running this playbook towards virtual nodes in Cisco Modeling Labs.

My Test inventory:

all:
  hosts:
    test_device:
      ansible_network_os: ios
      ansible_user: user@a1234/n4/0
      ansible_host: 127.0.0.1
      ansible_port: 3000
      ansible_become: yes
      ansible_become_method: enable

Test-playbook:

- name: Example to showcase playbook not leaving configuration mode
  hosts: test_device
  gather_facts: no
  connection: network_cli

  tasks:
  - name: Push new configuration
    cisco.ios.ios_config:
      lines:
        vrf definition Test description 'Failingcommand'"
    register: config_before

After this run, the terminal on the device will show the following:

Test-Device(config)#vrf definition Test description 'Failingcommand'"
vrf definition Test description 'Failingcommand'"
                    ^
% Invalid input detected at '^' marker.

Test-Device(config)#

I have attached the traceback from the verbose output as a file, due to it being a large output. Filename: failed_command.txt

Running playbook again with corret Syntax

We have now fixed the syntax error, and are running the playbook again.

  - name: Push new configuration
    cisco.ios.ios_config:
      lines:
        - vrf definition Test
        - description "Failingcommand"
    register: config_before

It will result in the following console error:

Test-DeviceE(config)#
Test-Device(config)#terminal length 0
terminal length 0
         ^
% Invalid input detected at '^' marker.

Test-Device(config)#

I have also attached the verbose output as a file, with filename: failed_to_set_terminal.txt failed_command.txt failed_to_set_terminal.txt

KB-perByte commented 3 years ago

Hi @AliArfan, Looking at the output you shared, that should not be the case if all the collections are proper, as the given play is working fine at our end and we are unable to reproduce the issue. Can you share the list of the collections and the IOS version you are using? Thanks.

AliArfan commented 3 years ago

Hi ,

Below I have included the output from ansible-galaxy collection list

Collection                    Version
----------------------------- -------
ansible.netcommon             1.5.0
ansible.posix                 1.2.0
ansible.utils                 2.0.2
ansible.windows               1.4.0
arista.eos                    1.3.0
azure.azcollection            1.4.0
check_point.mgmt              2.0.0
chocolatey.chocolatey         1.0.2
cisco.aci                     2.0.0
cisco.asa                     1.0.4
cisco.intersight              1.0.12
cisco.ios                     1.3.0
cisco.iosxr                   1.2.1
cisco.meraki                  2.2.1
cisco.mso                     1.1.0
cisco.nso                     1.0.3
cisco.nxos                    1.4.0
cisco.ucs                     1.6.0
cloudscale_ch.cloud           2.1.0
containers.podman             1.4.4
cyberark.conjur               1.1.0
cyberark.pas                  1.0.6
dellemc.openmanage            3.2.0
dellemc.os10                  1.1.1
dellemc.os6                   1.0.7
dellemc.os9                   1.0.4
f5networks.f5_modules         1.8.1
fortinet.fortimanager         2.0.1
fortinet.fortios              1.1.9
frr.frr                       1.0.3
gluster.gluster               1.0.1
google.cloud                  1.0.2
hetzner.hcloud                1.3.1
ibm.qradar                    1.0.3
infinidat.infinibox           1.2.4
inspur.sm                     1.1.2
junipernetworks.junos         1.3.0
kubernetes.core               1.2.0
mellanox.onyx                 1.0.0
netapp.aws                    20.9.0
netapp.elementsw              20.11.0
netapp.ontap                  21.3.1
netapp_eseries.santricity     1.1.0
netbox.netbox                 2.1.0
ngine_io.cloudstack           2.0.0
ngine_io.exoscale             1.0.0
ngine_io.vultr                1.1.0
openstack.cloud               1.3.0
openvswitch.openvswitch       1.2.0
ovirt.ovirt                   1.4.1
purestorage.flasharray        1.7.0
purestorage.flashblade        1.5.0
sensu.sensu_go                1.9.3
servicenow.servicenow         1.0.4
splunk.es                     1.0.2
t_systems_mms.icinga_director 1.16.0
theforeman.foreman            1.5.1
vyos.vyos                     1.1.1
wti.remote                    1.0.1

Thank you,

KB-perByte commented 3 years ago

Hi @AliArfan, The latest cisco.ios version is 2.3.1 can you please update your collections to the latest ones and check if you are facing the same issue? Given your issue is not being reproduced at our end this should give us a better understanding.

AliArfan commented 3 years ago

Hi,

I have now updated the collection, but the same behavior occurs. As mentoined earlier, the playbook is ran towards virtual nodes in Cisco Modeling Labs(CML). If this issue cannot be replicated using pyshical devices, perhaps it is releated to how CML handles the SSH connection as a connection to the device's terminal is opened after SSHing in.

Please let me know your input on this.

KB-perByte commented 3 years ago

Hi @AliArfan, That should not be the case in any given environment, are you facing a similar issue with any other commands?

AliArfan commented 3 years ago

HI @KB-perByte,

Any given command under "lines" that has a syntax error or is invalid will produce the same result. For example, "command does not exist". Also tried out the cisco.ios.ios_command module, but seems like there we have to specify to enter configuration mode, and perhaps leave it too.

KB-perByte commented 3 years ago

hey @AliArfan command modules are just there for commands that give you back some information, For pushing config to the device using ios_config is specifically recommended.

KB-perByte commented 3 years ago

Hey @AliArfan as the issue is inactive and is waiting on the info we’re closing the issue, please reopen a new issue if you’re still facing a similar issue.