From 7badb4a25bad61832c2b4aebe03a8488174fa307 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Thu, 31 Jan 2019 23:55:50 +0000 Subject: [PATCH] ansible: hacky parser to alow bools to be specified on command line --- ansible_mitogen/connection.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index ef03dae9..6e072a80 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -70,6 +70,16 @@ def optional_int(value): return None +def convert_bool(obj): + if isinstance(obj, bool): + return obj + if str(obj).lower() in ('no', 'false', '0'): + return False + if str(obj).lower() not in ('yes', 'true', '1'): + raise ValueError('expected yes/no/true/false/0/1, got %r' % (obj,)) + return True + + def default(value, default): """ Return `default` is `value` is :data:`None`, otherwise return `value`. @@ -112,7 +122,9 @@ def _connect_ssh(spec): 'check_host_keys': check_host_keys, 'hostname': spec.remote_addr(), 'username': spec.remote_user(), - 'compression': default(spec.mitogen_ssh_compression(), True), + 'compression': convert_bool( + default(spec.mitogen_ssh_compression(), True) + ), 'password': spec.password(), 'port': spec.port(), 'python_path': spec.python_path(),