From 299a5e4af3cd776b1d2405b28ca1c1328e282dba Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Mon, 22 Oct 2018 12:58:48 -0500 Subject: [PATCH] fix error checking if netns exists (#47397) This patch fixes an error that occurs when attempting to see if the netns already exists on the remote device. This change will now execute `ip netns list` and check if the desired namespace is in the output. Signed-off-by: Peter Sprygada --- lib/ansible/modules/net_tools/ip_netns.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/net_tools/ip_netns.py b/lib/ansible/modules/net_tools/ip_netns.py index e4a553e17c..9eda57cf99 100644 --- a/lib/ansible/modules/net_tools/ip_netns.py +++ b/lib/ansible/modules/net_tools/ip_netns.py @@ -61,6 +61,7 @@ RETURN = ''' ''' from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils._text import to_text class Namespace(object): @@ -77,9 +78,10 @@ class Namespace(object): def exists(self): '''Check if the namespace already exists''' - rtc, out, err = self._netns(['exec', self.name, 'ls']) - if rtc != 0: - self.module.fail_json(msg=err) + rc, out, err = self.module.run_command('ip netns list') + if rc != 0: + self.module.fail_json(msg=to_text(err)) + return self.name in out def add(self): '''Create network namespace'''