Skip to main content
Tauri
Explorer II
April 9, 2025
Solved

How to pass "y" when using purge command in CLI or JINJA template?

  • April 9, 2025
  • 3 replies
  • 1383 views

Hi!
I'm struggling with CLI template in FortiManager right now. I must delete all dhcp servers and I made script where I use purge command, but the problem  is, it gets stuck there. There is prompt where user must press y to confirm what you are doing, but I cant make it work in the script. When i copy that script manually to FortiGate then it works.

I read from other posts that few people got it work when they used \ny after purge command or added y below the command or right before end command "yend". All these ways didn't work for me. I also tried both CLI and JINJA template

Best answer by Tauri

Thanks, but it won't work. I found out that. Fmg 7.4 have bug that if I import device then i can't save Fmg configuration until Devices are up and config status shows synced. Then I can click save and manually install policy package to push changes into FortiGate. Otherwise it gave me error eg dhcp server 1 not found or smth similiar.

3 replies

joshbergm
Explorer
April 11, 2025

Hi,

 

The purge command indeed required yes to be executed.

However, you can try using a loop to go trough all of the available DHCP servers.

ChatGPT example:
{% for id in [1, 2, 3, 4] %}
config system dhcp server
delete {{ id }}
end
{% endfor %}

Hope it helps!

Tauri
TauriAuthorAnswer
Explorer II
April 11, 2025

Thanks, but it won't work. I found out that. Fmg 7.4 have bug that if I import device then i can't save Fmg configuration until Devices are up and config status shows synced. Then I can click save and manually install policy package to push changes into FortiGate. Otherwise it gave me error eg dhcp server 1 not found or smth similiar.

ede_pfau
SuperUser
SuperUser
April 12, 2025

How about:

- on the FGT, "conf sys dhcp server - purge - y - exit"

- then re-import the FGT into FMG (Dashboard, config widget, revisions, retrieve config)

- then push new DHCP config

 

That's the way I had to do it, numerous times. This is really an omission in FMG.

 

IF, and only if, you know the number of DHCP server configured in advance, say 50, then you could run a script to delete them one by one, as suggested. But if you are only 1 off, the script will crash.

config system dhcp server

{% for id in range(1, 50) %}
    delete {{ id }}
{% endfor %}

end

 

Remember, jinja2 is based on Python. ChatGPT produces nonsense.

Thought Leadership. Security Summit. Thursday, November 12th, PGA National Resort, Palm Beach Gardens, FL.
Thought Leadership. Security Summit. Thursday, October 8th. Disney's Grand Californian Hotel & SPA, Anaheim, CA.