Hi,
I've tried to configure Cisco smartport macros via ansible mit ios_config/cli_config.
Both failed with an timeout.
It looks like this on the serial console:
TN_00sw03(config)#macro auto execute TEST1_CISCO_SWITCH {
{..} > if [[ $LINKUP == YES ]]
then.else.fi> then
then.else.fi> conf t
then.else.fi> interface $INTERFACE
then.else.fi> description linkupmacro
then.else.fi> exit
then.else.fi> end
then.else.fi> fi
{..} > if [[ $LINKUP == NO ]]
then.else.fi> then
then.else.fi> conf t
then.else.fi> interface $INTERFACE
then.else.fi> description linkdownmacro
then.else.fi> exit
then.else.fi> end
then.else.fi> fi
{..} >}
TN_00sw03(config)#exit
My Playbook:
---
- name : set Macros
hosts: switches
connection: network_cli
gather_facts: true
tasks:
- debug:
msg: "{{lookup('template', 'test1.j2')}}"
- name: cli test
cli_config:
config: "{{lookup('template', 'test1.j2')}}"
multiline_delimiter: "@"
macro auto execute TEST1_CISCO_SWITCH {
if [[ $LINKUP == YES ]]
then
conf t
interface $INTERFACE
description linkupmacro
exit
end
fi
if [[ $LINKUP == NO ]]
then
conf t
interface $INTERFACE
description linkdownmacro
exit
end
fi
}
@
Ansible console output:
~/dev/cisco_ios_macros ansible-playbook set_macros.yml -l TN_00sw03 -k -u ansible -v
PLAY [set Macros] *********************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************
ok: [TN_00sw03.spm.local]
TASK [debug] **************************************************************************************************************************************************
ok: [TN_00sw03] => {
"msg": "macro auto execute TEST1_CISCO_SWITCH { \n if [[ $LINKUP == YES ]] \n then \n conf t \n interface $INTERFACE \n description linkupmacro \n exit \n end \n fi \n if [[ $LINKUP == NO ]] \n then \n conf t \n interface $INTERFACE \n description linkdownmacro \n exit \n end \n fi \n} \n@\n"
}
TASK [cli test] ***********************************************************************************************************************************************
fatal: [TN_00sw03]: FAILED! => {"changed": false, "msg": "timeout value 30 seconds reached while trying to send command: b'macro auto execute TEST1_CISCO_SWITCH {'"}
PLAY RECAP ****************************************************************************************************************************************************
TN_00sw03 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
It does not work either with ios_config nor cli_config. It always times out. I think it's due to the prompt which is different to the usual cisco prompt.
Anyone who knows an solution?
Bye