Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 136737f

Browse files
committedMay 8, 2024·
WIP
1 parent be709c1 commit 136737f

File tree

5 files changed

+120
-21
lines changed

5 files changed

+120
-21
lines changed
 

‎ansible_mitogen/transport_config.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,11 @@ def python_path(self, rediscover_python=False):
475475
rediscover_python=rediscover_python)
476476

477477
def host_key_checking(self):
478-
val = (
479-
self._connection.get_task_var('ansible_ssh_host_key_checking')
480-
or self._connection.get_task_var('ansible_host_key_checking')
481-
or C.HOST_KEY_CHECKING
482-
)
478+
def candidates():
479+
yield self._connection.get_task_var('ansible_ssh_host_key_checking')
480+
yield self._connection.get_task_var('ansible_host_key_checking')
481+
yield C.HOST_KEY_CHECKING
482+
val = next(v for v in candidates() if v is not None)
483483
return ansible.module_utils.parsing.convert_bool.boolean(val)
484484

485485
def private_key_file(self):
@@ -709,11 +709,11 @@ def python_path(self, rediscover_python=False):
709709
rediscover_python=rediscover_python)
710710

711711
def host_key_checking(self):
712-
val = (
713-
self._host_vars.get('ansible_ssh_host_key_checking')
714-
or self._host_vars.get('ansible_ssh_host_key_checking')
715-
or C.HOST_KEY_CHECKING
716-
)
712+
def candidates():
713+
yield self._host_vars.get('ansible_ssh_host_key_checking')
714+
yield self._host_vars.get('ansible_host_key_checking')
715+
yield C.HOST_KEY_CHECKING
716+
val = next(v for v in candidates() if v is not None)
717717
return ansible.module_utils.parsing.convert_bool.boolean(val)
718718

719719
def private_key_file(self):

‎tests/ansible/hosts/transport_config.hosts

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tc_become
1313
tc_become_method
1414
tc_become_pass
1515
tc_become_user
16+
tc_host_key_checking
1617
tc_password
1718
tc_port
1819
tc_remote_addr
@@ -74,6 +75,11 @@ tc-become-pass-password ansible_become_password=apassword
7475
tc-become-pass-pass ansible_become_pass=apass
7576
tc-become-pass-both ansible_become_pass=bpass ansible_become_password=bpassword
7677

78+
[tc_host_key_checking]
79+
tc-hkc-unset
80+
tc-hkc-host-key-checking ansible_host_key_checking=true
81+
tc-hkc-ssh-host-key-checking ansible_ssh_host_key_checking=true
82+
7783
[tc_port]
7884
tc-port-unset
7985
tc-port-explicit-port ansible_port=1234

‎tests/ansible/integration/transport_config/all.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- import_playbook: become_pass.yml
33
- import_playbook: become_user.yml
44
- import_playbook: become.yml
5+
- import_playbook: host_key_checking.yml
56
- import_playbook: password.yml
67
- import_playbook: port.yml
78
- import_playbook: python_path.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Each case is followed by mitogen_via= case to test hostvars method.
2+
3+
- name: integration/transport_config/host_key_checking.yml
4+
hosts: tc-hkc-unset
5+
tasks:
6+
- include_tasks: ../_mitogen_only.yml
7+
- {mitogen_get_stack: {}, register: out}
8+
- assert:
9+
that:
10+
- out.result | length == 1
11+
- out.result[0].method == "ssh"
12+
- out.result[0].kwargs.check_host_keys == "ignore"
13+
fail_msg: out={{ out }}
14+
tags:
15+
- mitogen_only
16+
17+
- hosts: tc-hkc-unset
18+
vars:
19+
mitogen_via: tc-hkc-host-key-checking
20+
tasks:
21+
- include_tasks: ../_mitogen_only.yml
22+
- {mitogen_get_stack: {}, register: out}
23+
- assert:
24+
that:
25+
- out.result | length == 2
26+
- out.result[0].method == "ssh"
27+
- out.result[0].kwargs.check_host_keys == "enforce"
28+
- out.result[1].method == "ssh"
29+
- out.result[1].kwargs.check_host_keys == "ignore"
30+
fail_msg: out={{ out }}
31+
tags:
32+
- mitogen_only
33+
34+
35+
- hosts: tc-hkc-host-key-checking
36+
tasks:
37+
- include_tasks: ../_mitogen_only.yml
38+
- {mitogen_get_stack: {}, register: out}
39+
- assert:
40+
that:
41+
- out.result | length == 1
42+
- out.result[0].method == "ssh"
43+
- out.result[0].kwargs.check_host_keys == "enforce"
44+
fail_msg: out={{ out }}
45+
tags:
46+
- mitogen_only
47+
48+
- hosts: tc-hkc-host-key-checking
49+
vars:
50+
mitogen_via: tc-hkc-unset
51+
tasks:
52+
- include_tasks: ../_mitogen_only.yml
53+
- {mitogen_get_stack: {}, register: out}
54+
- assert:
55+
that:
56+
- out.result | length == 2
57+
- out.result[0].method == "ssh"
58+
- out.result[0].kwargs.check_host_keys == "ignore"
59+
- out.result[1].method == "ssh"
60+
- out.result[1].kwargs.check_host_keys == "enforce"
61+
fail_msg: out={{ out }}
62+
tags:
63+
- mitogen_only
64+
65+
66+
- hosts: tc-hkc-ssh-host-key-checking
67+
tasks:
68+
- include_tasks: ../_mitogen_only.yml
69+
- {mitogen_get_stack: {}, register: out}
70+
- assert:
71+
that:
72+
- out.result | length == 1
73+
- out.result[0].method == "ssh"
74+
- out.result[0].kwargs.check_host_keys == "enforce"
75+
fail_msg: out={{ out }}
76+
tags:
77+
- mitogen_only
78+
79+
- hosts: tc-hkc-ssh-host-key-checking
80+
vars:
81+
mitogen_via: tc-hkc-unset
82+
tasks:
83+
- include_tasks: ../_mitogen_only.yml
84+
- {mitogen_get_stack: {}, register: out}
85+
- assert:
86+
that:
87+
- out.result | length == 2
88+
- out.result[0].method == "ssh"
89+
- out.result[0].kwargs.check_host_keys == "ignore"
90+
- out.result[1].method == "ssh"
91+
- out.result[1].kwargs.check_host_keys == "enforce"
92+
fail_msg: out={{ out }}
93+
tags:
94+
- mitogen_only

‎tests/ansible/regression/issue_1066__add_host__host_key_checking.yml

+9-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
- name: Add hosts dynamically
77
add_host:
88
name: "{{ item.name }}"
9-
ansible_host_key_checking: "{{ item.host_key_checking }}"
9+
ansible_host_key_checking: "{{ item.host_key_checking | default(omit) }}"
10+
ansible_ssh_host_key_checking: "{{ item.host_ssh_key_checking | default(omit) }}"
1011
ansible_host: "{{ hostvars[inventory_hostname].ansible_host | default(omit) }}"
1112
ansible_password: "{{ hostvars[inventory_hostname].ansible_password | default(omit) }}"
1213
ansible_port: "{{ hostvars[inventory_hostname].ansible_port | default(omit) }}"
@@ -15,12 +16,14 @@
1516
loop:
1617
- {name: issue-1066-host-hkc-false, host_key_checking: false}
1718
- {name: issue-1066-host-hkc-true, host_key_checking: true}
19+
- {name: issue-1066-host-hskc-false, host_ssh_key_checking: false}
20+
- {name: issue-1066-host-hskc-true, host_ssh_key_checking: true}
1821
delegate_to: localhost
1922
tags:
2023
- issue_1066
2124

2225
- name: regression/issue_1066__add_host__host_key_checking.yml
23-
hosts: issue-1066-host-hkc-false,issue-1066-host-hkc-true
26+
hosts: issue-1066-host-*
2427
gather_facts: false
2528
become: false
2629
serial: 1
@@ -47,19 +50,14 @@
4750
- name: Confirm dynamically added hosts are/are not reachable
4851
vars:
4952
expected:
50-
# Host key checking explicitly disabled, therefore connection succeeds
51-
issue-1066-host-hkc-false:
52-
ansible_host_key_checking: false
53-
# Host key checking explicitly enabled, therefore connection fails
54-
issue-1066-host-hkc-true:
55-
ansible_host_key_checking: true
56-
unreachable: true
53+
issue-1066-host-hkc-false: {}
54+
issue-1066-host-hkc-true: {unreachable: true}
55+
issue-1066-host-hskc-false: {}
56+
issue-1066-host-hskc-true: {unreachable: true}
5757
assert:
5858
that:
5959
- issue_1066_ping.unreachable is defined == expected[inventory_hostname].unreachable is defined
6060
- issue_1066_ping.unreachable | default(42) == expected[inventory_hostname].unreachable | default(42)
61-
- ansible_host_key_checking is defined
62-
- ansible_host_key_checking == expected[inventory_hostname].ansible_host_key_checking
6361
# ansible_host_key_checking don't work on Vanilla Ansible 2.10, even for
6462
# static inventory hosts (ansible/ansible#49254, ansible/ansible#73708).
6563
when:

0 commit comments

Comments
 (0)
Please sign in to comment.