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
Solved! Go to Solution.
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.
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!
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.
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.
User | Count |
---|---|
2279 | |
1242 | |
772 | |
452 | |
405 |
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2025 Fortinet, Inc. All Rights Reserved.