From 22150fd388ee940ad6c468bc3ca7483ca8e4bd3d Mon Sep 17 00:00:00 2001 From: genofire Date: Mon, 8 May 2023 13:55:42 +0000 Subject: [PATCH] fix: kill dhclient process when interface was dhcp --- plugins/module_utils/interface.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/module_utils/interface.py b/plugins/module_utils/interface.py index 08db349e..70ac7c8a 100644 --- a/plugins/module_utils/interface.py +++ b/plugins/module_utils/interface.py @@ -220,9 +220,18 @@ def _copy_and_update_target(self): if changed: if self.params['enable']: self.setup_interface_cmds += "interface_bring_down('{0}', false);\n".format(self.target_elt.tag) + + # possibly kill remaining dhclient process + if 'ipaddr' in before and before['ipaddr'] == 'dhcp': + self.setup_interface_cmds += "kill_dhclient_process(get_real_interface({0}));\n".format(self.target_elt.tag) + + self.setup_interface_cmds += "interface_configure('{0}', true);\n".format(self.target_elt.tag) else: self.setup_interface_cmds += "interface_bring_down('{0}', true);\n".format(self.target_elt.tag) + # possibly kill remaining dhclient process + if 'ipaddr' in before and before['ipaddr'] == 'dhcp': + self.setup_interface_cmds += "kill_dhclient_process(get_real_interface({0}));\n".format(self.target_elt.tag) return (before, changed)