netmiko
netmiko copied to clipboard
Fortigate: Search pattern never detected in send_command_expect
I am trying to send some config lines with Netmiko to a Fortigate firewall. These are the lines I am sending:
config global
config system interface
edit "b_t666_vl666"
set vdom "BLUE"
set ip 8.8.8.1 255.255.255.252
set type vlan
set interface "ag1_int"
set vlanid 666
set alias "test_t666_vl666"
end
end
When I try to push the same config via netmiko, I get the below error message:
Traceback (most recent call last):
File "/root/.ansible/tmp/ansible-local-2383c0yw6152/ansible-tmp-1594995400.8889592-219300089313818/AnsiballZ_fortios_ssh.py", line 102, in <module>
_ansiballz_main()
File "/root/.ansible/tmp/ansible-local-2383c0yw6152/ansible-tmp-1594995400.8889592-219300089313818/AnsiballZ_fortios_ssh.py", line 94, in _ansiballz_main
invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
File "/root/.ansible/tmp/ansible-local-2383c0yw6152/ansible-tmp-1594995400.8889592-219300089313818/AnsiballZ_fortios_ssh.py", line 40, in invoke_module
runpy.run_module(mod_name='ansible.modules.network.fortios_ssh', init_globals=None, run_name='__main__', alter_sys=True)
File "/usr/lib64/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/tmp/ansible_fortios_ssh_payload__ow_58y5/ansible_fortios_ssh_payload.zip/ansible/modules/network/fortios_ssh.py", line 130, in <module>
File "/tmp/ansible_fortios_ssh_payload__ow_58y5/ansible_fortios_ssh_payload.zip/ansible/modules/network/fortios_ssh.py", line 72, in send_lines
File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 1337, in send_command
search_pattern
OSError: Search pattern never detected in send_command_expect: Fw1_prd_r3b15_ams7\ \#
I extracted the relevant bits of the code where netmiko comes into play:
connection = {
'device_type': 'fortinet',
device_conn: device,
'username': username,
'password': password,
'port': port,
'global_delay_factor': 2,
}
try:
ssh_session = netmiko.ConnectHandler(**connection)
except Exception as exception:
module.fail_json(msg=exception)
return ssh_session
for line in config_lines:
cmd_output = ssh_session.send_command(line)
ssh_session.disconnect()
I have also tried to add ssh_session.send_command_timing('config global', delay_factor=4)
on my code, before to push the config lines but the error remain
OSError: Search pattern never detected in send_command_expect: Fw1_prd_r3b15_ams7\ \(global\)\ \#
Netmiko uses output of the command "get system status | grep Virtual" to dectect if Fortigate box works in multi VDOM mode. FortiOS v6.0.x and v6.2.x have different outputs for that command:
- v6.0.x
test-fg # get system status | grep Virtual
Virtual domains status: 3 in NAT mode, 0 in TP mode
Virtual domain configuration: enable
test-fg #
- v6.2.x
test-fg # get system status | grep Virtual
Virtual domains status: 7 in NAT mode, 0 in TP mode
Virtual domain configuration: multiple
test-fg #
@lvrfrc87 , can you confirm your FortiOS version?
@greenfox878
FortiGate 3100D
v6.4.1 build1637 (GA)
@lvrfrc87 , thank you! Defenitely, changed output is root of the issue. FortiOS 6.2.0 and later has three vdom related options:
- disabled
- mult-vdom
- split-vdom
A possible soulution greenfox878@89781d02ede858674b48aa91d2c212379010ab28 tested on 6.2.4 and 6.0.9
@greenfox878 Do you want to submit a pull-request on that?
@ktbyers , no problem. I will wait for reply from @lvrfrc87 or 1-2 days, then submit PR.
@greenfox878 Unfortunately I do not have chance to try you anytime soon but I will keep you posted in case
Updated Fortinet PR here:
https://github.com/ktbyers/netmiko/pull/3091
If someone is available/willing to test it.