-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix add_hosts when ansible_host_key_checking is passed to the new host #1067
Conversation
@philfry I wrote a test case, which uncovered an additional problem code path
so I've built upon your PR in PR #1069.
|
Yes, I just tested it successfully on my machines.
I rebased my PR against the current master and added your commit 8a95c70. I hope that's what you meant.
Gladly 😃 |
D'oh! I meant #1070, which also includes the new test 207f4f2 and my adaptation of your fix be709c1. Sorry for the confusion.
Turns out you're already in there :). |
Hi Alex, the reason for the (ugly) list/filter construct was because in my tests I was getting odd results otherwise. Take a look at this: #!/usr/bin/python3
# stripped down version of ansible's "boolean"
BOOLEANS_TRUE = frozenset(('y', 'yes', 'on', '1', 'true', 't', 1, 1.0, True))
BOOLEANS_FALSE = frozenset(('n', 'no', 'off', '0', 'false', 'f', 0, 0.0, False))
def boolean(value):
if isinstance(value, bool):
return value
normalized_value = str(value).lower()
if normalized_value in BOOLEANS_TRUE:
return True
elif normalized_value in BOOLEANS_FALSE:
return False
# host_key_checking from pr1070
def pr1070(a, b, c):
val = (a or b or c)
return boolean(val)
# ansible_ssh_host_key_checking from pr1067
# not exactly the same because C.HOST_KEY_CHECKING is evaluated outside of this function,
# it's just to get the idea
def pr1067(a, b, c):
tmp = [boolean(x) for x in list(
filter(lambda x:x is not None, (a, b, c))
)]
if not tmp: return None
return any(tmp)
# build a random matrix
matrix = []
for a in None, 'yes', 0:
for b in None, 1, False:
for c in None, True, False:
matrix += [(a, b, c)]
# compare methods
for t in matrix:
alex = pr1070(*t)
phil = pr1067(*t)
if alex != phil: print(f"{t}, alex: {alex}, phil: {phil}")
else: print(t) This results in
So some combinations of Take this slightly modified playbook: ---
- hosts: localhost
gather_facts: no
tasks:
- add_host:
name: ansible-test-100
ansible_host: 192.168.122.100
ansible_ssh_private_key_file: /tmp/ansibletest-leases/100/id_ed25519
ansible_host_key_checking: '{{chk}}'
- hosts: ansible-test-100
gather_facts: no
remote_user: ansible
become: no
tasks:
- ping: and run it with Adding some debug lines to #1070: --- i/ansible_mitogen/transport_config.py
+++ w/ansible_mitogen/transport_config.py
@@ -475,11 +475,17 @@ class PlayContextSpec(Spec):
rediscover_python=rediscover_python)
def host_key_checking(self):
+ print(f"""
+ ansible_ssh_host_key_checking: {self._connection.get_task_var('ansible_ssh_host_key_checking')}
+ ansible_host_key_checking: {self._connection.get_task_var('ansible_host_key_checking')}
+ C.HOST_KEY_CHECKING: {C.HOST_KEY_CHECKING}
+ """)
val = (
self._connection.get_task_var('ansible_ssh_host_key_checking')
or self._connection.get_task_var('ansible_host_key_checking')
or C.HOST_KEY_CHECKING
)
+ print(f"val: {val}")
return ansible.module_utils.parsing.convert_bool.boolean(val)
def private_key_file(self): →
It's probably not very common passing "real" boolean arguments to Ansible, but older versions of Ansible had some bugs here that forced me to use them. FWIW: You can get a "real" What do you think, should we ignore this and take the #1070 code or could this become a problem in the future? Another approach could be this: def host_key_checking(self):
val = [ansible.module_utils.parsing.convert_bool.boolean(x) for x in list(
filter(lambda x:x is not None, (
self._connection.get_task_var('ansible_ssh_host_key_checking'),
self._connection.get_task_var('ansible_host_key_checking'),
C.HOST_KEY_CHECKING,
True
)))]
return val[0] This preserves priorities and, for sanity, has a default value of |
# ansible_ssh_host_key_checking from pr1067
# modified
def pr1067(a, b, c):
tmp = [boolean(x) for x in list(
filter(lambda x:x is not None, (a, b, c, True))
)]
return tmp[0] →
|
I've updated #1070. I think it accounts for mitogen/ansible_mitogen/transport_config.py Lines 477 to 483 in 5749845
|
That looks pretty good! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one cosmetic, then I'm happy. I'll rerun any flaky CI jobs (#1058) as needed.
adding new hosts to the inventory using 'add_hosts' Co-authored-by: Alex Willmer <[email protected]>
Some tests were being incorrectly excluded. Including those that use `add_host`. refs mitogen-hq#1066, mitogen-hq#1069
0a042e3
to
60f8682
Compare
…in inventory
related to #1066