ansible-collections / cisco.ios

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

Custom macros #578

Open SanBern opened 2 years ago

SanBern commented 2 years ago
SUMMARY

We are facing an issue while deploying auto smartports macros. In our environment the whole configuration is normally pushed via Ansible and netconf. since I haven't found a way to deploy the macros with netconf yet, I switched to network_cli and ios_config in ansible.

And here we facing a Problem the macro is generated by a jinja2 template and looks like this:

macro auto execute ADSL-Green { if [[ $LINKUP == YES ]] then conf t interface $INTERFACE Description $TRIGGER macro description $TRIGGER switchport access vlan 100 authentication event server dead action authorize vlan 100 authentication event no-response action authorize vlan 100 exit fi if [[ $LINKUP == NO ]] then conf t interface $INTERFACE no macro description $TRIGGER description dot1x-$TRIGGER-last-used exit fi } ....

ISSUE TYPE
COMPONENT NAME

ios_config

ANSIBLE VERSION
ansible 2.9.27
IOS

16.12r up to 16.12.04 17.03.05

STEPS TO REPRODUCE
- name: CHECK IF FINAL CLI CONFIG EXIST
   stat:
     path: "{{ config_dir }}/{{inventory_hostname}}/cli/{{inventory_hostname}}-access-macros.conf"
   register: global_config

 - name: PUSH FINAL CLI CONFIG
   ios_config:
     src: "{{ config_dir }}/{{inventory_hostname}}/cli/{{inventory_hostname}}-access-macros.conf"
   when: global_config.stat.exists
ACTUAL RESULTS
"ansible.module_utils.connection.ConnectionError: timeout value 60 seconds reached while trying to send command: b'macro auto execute ADSL-Green {'\n",
"module_stdout": "",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error"

i have written a script in python to debug with netmiko:

netmiko.exceptions.ReadTimeout:
Pattern not detected: '(?:switch\\-2.*$|#.*$)' in output.

Netmiko debug: ---------------------------------------- 
switch(config)# 
DEBUG:netmiko:Pattern found: (#) 
switch(config)# 
DEBUG:netmiko:write_channel: b'macro auto execute ADSL-Green {\n' 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: 
macro DEBUG:netmiko:read_channel: auto 
DEBUG:netmiko:read_channel: execut 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: e ADS 
DEBUG:netmiko:read_channel: L-Gree 
DEBUG:netmiko:read_channel: n { {..} > 
DEBUG:netmiko:Pattern found: (macro\ auto\ execute\ ADSL\-Green\ \{) macro auto execute ADSL-Green { DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel: 
DEBUG:netmiko:read_channel

it looks like ansible doesn't understand the macro prompt {..} > and then falls into a timeout

Workaround

in order to push the macro nevertheless, I am currently using a python script with netmiko in which I set cmd_verify=flase in the send config.

output = net_connect.send_config_set(lines,cmd_verify=False)

RobinBeismann commented 1 year ago

@SanBern did you find a solution to this?

ollylawrence commented 1 year ago

Any progress on this ? I am hitting the same issue.

Given that wen you enter the macro enter mode the prompt is not the standard config one this is probably where this fails.

Might even need a new module to deal with this like the ios_banner module as that deals with a similar situation.

SanBern commented 1 year ago

Unfortunately no, I still push the macros separately with the python script.