Skip to content

Commit 207f4f2

Browse files
committed
tests: Add regression for add_host with host_key_checking
refs mitogen-hq#1066
1 parent 0f34e25 commit 207f4f2

File tree

4 files changed

+81
-4
lines changed

4 files changed

+81
-4
lines changed

tests/ansible/ansible.cfg

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
[defaults]
22
any_errors_fatal = true
3-
# callback_whitelist naming will be deprecated in ansible-core >= 2.15.
4-
# callbacks_enabled naming was added in ansible-core 2.11
3+
# callbacks_enabled was added in Ansible 4 (ansible-core 2.11).
54
# profile_tasks: Displays timing for each task and summary table of top N tasks
65
# timer: Displays "Playbook run took 0 days, 0 hours, ..."
6+
callbacks_enabled =
7+
profile_tasks,
8+
timer
9+
# callback_whitelist was deprecated in Ansible >= 8 (ansible-core >= 2.15).
710
callback_whitelist =
811
profile_tasks,
912
timer
@@ -37,7 +40,9 @@ no_target_syslog = True
3740
# Required by integration/ssh/timeouts.yml
3841
timeout = 30
3942

40-
# On Travis, paramiko check fails due to host key checking enabled.
43+
# Ideally this would be true here and and overridden for hosts/groups. However
44+
# ansible_host_key_checking don't work on Vanilla Ansible 2.10, even for
45+
# static inventory hosts (ansible/ansible#49254, ansible/ansible#73708)
4146
host_key_checking = False
4247

4348
[inventory]

tests/ansible/regression/all.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
- import_playbook: issue_655__wait_for_connection_error.yml
1616
- import_playbook: issue_776__load_plugins_called_twice.yml
1717
- import_playbook: issue_952__ask_become_pass.yml
18+
- import_playbook: issue_1066__add_host__host_key_checking.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
- name: regression/issue_1066__add_host__host_key_checking.yml
2+
hosts: test-targets[0]
3+
gather_facts: false
4+
become: false
5+
tasks:
6+
- name: Add hosts dynamically
7+
add_host:
8+
name: "{{ item.name }}"
9+
ansible_host_key_checking: "{{ item.host_key_checking }}"
10+
ansible_host: "{{ hostvars[inventory_hostname].ansible_host | default(omit) }}"
11+
ansible_password: "{{ hostvars[inventory_hostname].ansible_password | default(omit) }}"
12+
ansible_port: "{{ hostvars[inventory_hostname].ansible_port | default(omit) }}"
13+
ansible_python_interpreter: "{{ hostvars[inventory_hostname].ansible_python_interpreter | default(omit) }}"
14+
ansible_user: "{{ hostvars[inventory_hostname].ansible_user | default(omit) }}"
15+
loop:
16+
- {name: issue-1066-host-hkc-false, host_key_checking: false}
17+
- {name: issue-1066-host-hkc-true, host_key_checking: true}
18+
delegate_to: localhost
19+
tags:
20+
- issue_1066
21+
22+
- name: regression/issue_1066__add_host__host_key_checking.yml
23+
hosts: issue-1066-host-hkc-false,issue-1066-host-hkc-true
24+
gather_facts: false
25+
become: false
26+
serial: 1
27+
tasks:
28+
- meta: reset_connection
29+
30+
# The host key might be in ~/.ssh/known_hosts. If it's removed then no
31+
# problem - test-targets hosts have host_key_checking=false.
32+
- name: Remove existing host keys
33+
known_hosts:
34+
name: "{{ ansible_host }}"
35+
state: absent
36+
delegate_to: localhost
37+
38+
- name: Ping dynamically added hosts
39+
ping:
40+
ignore_errors: true
41+
ignore_unreachable: true
42+
register: issue_1066_ping
43+
44+
- debug:
45+
var: issue_1066_ping
46+
47+
- name: Confirm dynamically added hosts are/are not reachable
48+
vars:
49+
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
57+
assert:
58+
that:
59+
- issue_1066_ping.unreachable is defined == expected[inventory_hostname].unreachable is defined
60+
- 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
63+
# ansible_host_key_checking don't work on Vanilla Ansible 2.10, even for
64+
# static inventory hosts (ansible/ansible#49254, ansible/ansible#73708).
65+
when:
66+
- ansible_version.full is version('2.11', '>=', strict=True)
67+
or is_mitogen
68+
tags:
69+
- issue_1066

tests/ansible/setup/report_controller.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- name: Report controller parameters
2-
hosts: localhost
2+
hosts: test-targets[0]
33
gather_facts: false
44
tasks:
55
- debug:
@@ -9,9 +9,11 @@
99
- $(groups): "{{ lookup('pipe', 'groups') }}"
1010
- $(pwd): "{{ lookup('pipe', 'pwd') }}"
1111
- $(whoami): "{{ lookup('pipe', 'whoami') }}"
12+
- ansible_inventory_sources: "{{ ansible_inventory_sources | default('<unset>') }}"
1213
- ansible_run_tags: "{{ ansible_run_tags | default('<unset>') }}"
1314
- ansible_playbook_python: "{{ ansible_playbook_python | default('<unset>') }}"
1415
- ansible_skip_tags: "{{ ansible_skip_tags | default('<unset>') }}"
1516
- ansible_version.full: "{{ ansible_version.full | default('<unset>') }}"
1617
- is_mitogen: "{{ is_mitogen | default('<unset>') }}"
1718
- playbook_dir: "{{ playbook_dir | default('<unset>') }}"
19+
delegate_to: localhost

0 commit comments

Comments
 (0)