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
ios_config fails when creating macro "timeout trying to send command:" #38420
Comments
Files identified in the description: If these files are inaccurate, please update the |
Just a guess but a macro is a multi-line command but does not allow you to choose the delimiter like "banner". So perhaps ansible its assuming the command should return a prompt or something instead of treating it as a multi-line command? The output of "macro name MYMACRO" is:
Config on switch is like:
|
Adding this to our feature idea list. There is a workaround by using the ios_config module and enter the command as one long line. |
I've raised #38591 to track giving an error message |
Perhaps I misunderstand is there an example of this somewhere? I have tried some variations to enter the whole thing as a single command but nothing has worked so far.
|
Had not known about this command, but this seems like another example of multi-line inputs such as with the banner commands. Instead of having another specially focused feature or module on macros, I'd propose to just have a detection for I did a quick test of this and was able to get this play to work (after fixing the structure issues in above), Willing to create the PR if this sounds like an acceptable approach. e.g.
|
I think a general method to handle multi-line inputs instead of only handling the "banner" command would be great. Does your solution work if your using "parents:macro name PHONE"? If you end up making a PR I would certainly be willing to help test it. |
@yaplej fwiw, on my 9500 it doesn't appear that a macro is indented, so parents would not apply. Which, IMHO is really broken on Cisco's part not to indent that. It doesn't for banner either. But that's the way it is. |
I tried the structural changes you mentioned but I was unable to get it to work. Still getting "timeout trying to send command: macro name PHONE"
I also updated to ansible 2.6.1 but no luck.
|
I'm still trying to get it to work in 2.6.2. Its a total hack job but it seems like its close to running. There is probably a much better solution like detecting the line "Enter macro commands one per line. End with the character '@'." and going into sendonly mode as previously mentioned but I was not sure where that could be done. In /modules/network/ios/ios_config.py created a modified function based on load_banners().
Temporarily send all commands through load_config2() function. Because I don't know what I am doing.
Using a very simple playbook. I had to take the '@' out of the play and add it as the delimiter in load_config2() because it kept getting stripped out of the updates.
It appears to run now but does not actually put the config on the device for some reason.
I am stumped why the updates are not actually getting executed on the device. I enable command logging on the device and can see nothing is getting executed. Another thing I noticed with macro's in general is that they cannot be modified without first removing them. So the "before" statement of 'no macro name WORD' must be executed before the macro is re-created. If the macro partially exists or is modified the "updates" section is missing the commands that were formerly on the device. |
@bdowling Your correct that the IOS does not indent anything under the macro command itself but you can manually indent them by prefixing the lines with a space or two when you enter them.
If you do that your able to treat each macro as a section in the config. With the exception of the terminating '@'.
|
I actually got it to work. No its not pretty. Created a new function to separate normal commands from macros.
Edit: Should be looking for 'macro name' not just 'macro'. Send all commands through load_config_or_macro() to filter out macros to load_macro().
Took all the lines from the macro and converted it into one big blob of commands similar to how the banner command is handled.
Edit: Adding the delimiter is not needed after fixing the replace block functionality by adding the 'parent:' to the play. The macro play had to get two lines quoted or else they were handled as 'None' or blank lines.
Edit: Replace block only works when used with 'parents:'. #29716 Edit: Tried using 'diff_ignore_lines:' for '@' and '#macro.*' does this work at all? #30562 Last thing is it needs improvement to be idempotent. I really do not want it to be running every time the play is executed but right now it seems to detect that the lines '#macro keyword.*' and '@' are different before each run. So I think the diff detection needs improved to handle macros better too. |
I am not sure how to make it idempotent. The difference is generated by candidate.difference() from the NetworkConfig class. In that it has DEFAULT_COMMENT_TOKENS and includes '#'. That is why the line '#macro keywords $DESCRIPTION' line is always detected as a difference/change. I was able to resolve the issue with '@' being detected as a change by moving that to 'after:' in the play. Putting each line in single quotes keeps '#macro keywords' line from being treated as 'None' so I put them all in quotes for consistency.
Edit: I confirmed by removing '#' from 'DEFAULT_COMMENT_TOKENS' in '/module_utils/network/common/config.py' and running my playbook again. This seems like a separate issue so I opened #43861.
|
ISSUE TYPE
COMPONENT NAME
ios_config
ANSIBLE VERSION
CONFIGURATION
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 30
OS / ENVIRONMENT
CentOS Linux release 7.4.1708 (Core)
Cisco IOS XE Software, Version 16.06.03
SUMMARY
ios_config timeout when sending "macro name MYMACRO" command
STEPS TO REPRODUCE
Rerun playbook
EXPECTED RESULTS
Creates the macro.
ACTUAL RESULTS
The text was updated successfully, but these errors were encountered: