- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to pass "y" when using purge command in CLI or JINJA template?
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.
- Labels:
-
FortiGate
-
FortiManager
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
