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'''