PackeTsar / freeztp

An Open-Source Zero-Touch Provisioning System for Cisco IOS.
GNU General Public License v3.0
216 stars 27 forks source link

Saving configuration to startup-config #97

Closed torbensp closed 1 year ago

torbensp commented 1 year ago

Hi!

I am trying to use FreeZTP together with some industrial switches (IE1000, IE2000, IE3300 and IE4010) and have currently a test setup with two IE3300. I am able to upload firmware as well as configuration but the config is not stored in the "startup-config" but instead in "running-config", whereby the ZTP process will start again each time I reboot the switches. As part of the FreeZTP configuration template, I have tried the add "write" command or "copy running-config to startup-config" but without any affect. If I take the generated configuration from FreeZTP and load it directly into the switch via the CLI, then there is no problem as the configuration is saved to "startup-config". Also, if I manually type "write" in the CLI, the config is stored correctly.

Under sted 5.4 in the description, I can see the following note.

NOTE: The switch does not save the new configurations into its startup-config. That has to be done manually

What does this actually mean and can it really be that you manually have to make a "write" via CLI to save the running config, whereby the switch will stop trying to auto provision via ZTP/PnP at each boot?

Best regards,

Torben

pschapman commented 1 year ago

That has to be done manually.

It's exactly as stated. If you want the configuration to persist through a restart, then you need to issue the appropriate command. This can be done via SSH after the baseline is deployed by ZTP or you can add a little spice to your config with some EEM (sample below).

event manager applet save_config authorization bypass
 event timer cron name save_config_cron cron-entry "* * * * *" maxrun 300
 action 010 comment Automatically remove this script and save config.
 action 020 cli command "enable"
 action 030 cli command "configure terminal"
 action 040 cli command "no event manager applet save_config"
 action 050 cli command "end"
 action 060 cli command "write mem" pattern "confirm|#"
 action 070 cli command ""
 action 080 cli command "exit"
torbensp commented 1 year ago

Hi Paul,

Many thanks for your quick response. Much appreciated!

With regards to above example EEM code, should it then just be added after the Cisco config within the ^ ^ block? Otherwise, can you explain a bit more where/how the EEM code can be included as part of the FreeZTP configuration.

Best regards,

Torben

pschapman commented 1 year ago

Hi - The EEM would be part of your config. If you manually insert it into a switch via CLI you will see that it shows up at the bottom of a show run output. PSC

torbensp commented 1 year ago

Hi Paul,

Thanks again for taking time to support me!

I have tried to add the following EEM code but it just does not seem to execute and the running config is not stored in the startup config.

! EEM script to copy running config to startup config event manager applet save_config authorization bypass event timer countdown time 10 action 010 comment Automatically remove this script and save config. action 020 cli command "enable" action 030 cli command "no event manager applet save_config" action 040 cli command "end" action 050 cli command "write mem" pattern "confirm|#" action 060 cli command "" action 070 cli command "end" action 080 cli command "exit"

Do you have idea why this is not working?

Another thing I can see is that I am getting this error each time I ZTP boot the device .

%ERROR:Software Installation Failed err_code:35

Any idea what this can be related to?

Br,

Torben

pschapman commented 1 year ago

Hi -

Doesn't help that I forgot "configure terminal" in the command set. Updated version in previous post now.

In ZTP, you would have a template like this:

ztp set template MY_TEMPLATE ^
! A bunch of config template stuff
! EEM applet(s)
end
^

Note that end at the end of your config template is generally mandatory. The switch may balk if that is absent.

PSC

torbensp commented 1 year ago

Hi Paul,

After debugging the EEM applet for some time, I got the following code which works and the running config is saved to start-up config.

ztp set template MY_TEMPLATE ^ ! A bunch of config template stuff

! EEM script to copy running config to startup config event manager applet save_config authorization bypass event timer countdown time 10 action 010 comment Automatically remove this script and save config. action 020 cli command "enable" action 025 cli command "configure terminal" action 030 cli command "no event manager applet save_config" action 040 cli command "end" action 050 cli command "write mem" pattern "confirm|#" action 060 cli command "" action 070 cli command "end" action 080 cli command "exit" ! exit ^

I still have the error mentioned in my earlier post which I am not sure what causes as things seems to work.

%ERROR:Software Installation Failed err_code:35

Any idea what this can be related to?

Br,

Torben

pschapman commented 1 year ago

Hi -

Realized that I had an unneeded "end" statement in the EEM. Removed from my comment above.

It looks like you are trying to do software updates via native mechanism. This, unfortunately, is unreliable.

ztp set imagefile NONE

Please review closed issues for this project regarding similar issues.

I also recommend this setting (if not the default):

ztp set logging merged-config-to-custom-file disable

PSC