-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1067 from philfry/host_key_checking
Fix add_hosts when ansible_host_key_checking is passed to the new host
- Loading branch information
Showing
12 changed files
with
215 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
tests/ansible/integration/transport_config/host_key_checking.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# Each case is followed by mitogen_via= case to test hostvars method. | ||
|
||
- name: integration/transport_config/host_key_checking.yml | ||
hosts: tc-hkc-unset | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 1 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "ignore" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only | ||
|
||
- hosts: tc-hkc-unset | ||
vars: | ||
mitogen_via: tc-hkc-host-key-checking | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 2 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "enforce" | ||
- out.result[1].method == "ssh" | ||
- out.result[1].kwargs.check_host_keys == "ignore" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only | ||
|
||
|
||
- hosts: tc-hkc-host-key-checking | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 1 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "enforce" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only | ||
|
||
- hosts: tc-hkc-host-key-checking | ||
vars: | ||
mitogen_via: tc-hkc-unset | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 2 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "ignore" | ||
- out.result[1].method == "ssh" | ||
- out.result[1].kwargs.check_host_keys == "enforce" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only | ||
|
||
|
||
- hosts: tc-hkc-ssh-host-key-checking | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 1 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "enforce" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only | ||
|
||
- hosts: tc-hkc-ssh-host-key-checking | ||
vars: | ||
mitogen_via: tc-hkc-unset | ||
tasks: | ||
- include_tasks: ../_mitogen_only.yml | ||
- {mitogen_get_stack: {}, register: out} | ||
- assert: | ||
that: | ||
- out.result | length == 2 | ||
- out.result[0].method == "ssh" | ||
- out.result[0].kwargs.check_host_keys == "ignore" | ||
- out.result[1].method == "ssh" | ||
- out.result[1].kwargs.check_host_keys == "enforce" | ||
fail_msg: out={{ out }} | ||
tags: | ||
- mitogen_only |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
tests/ansible/regression/issue_1066__add_host__host_key_checking.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
- name: regression/issue_1066__add_host__host_key_checking.yml | ||
hosts: test-targets[0] | ||
gather_facts: false | ||
become: false | ||
tasks: | ||
- name: Add hosts dynamically | ||
add_host: | ||
name: "{{ item.name }}" | ||
ansible_host_key_checking: "{{ item.host_key_checking | default(omit) }}" | ||
ansible_ssh_host_key_checking: "{{ item.host_ssh_key_checking | default(omit) }}" | ||
ansible_host: "{{ hostvars[inventory_hostname].ansible_host | default(omit) }}" | ||
ansible_password: "{{ hostvars[inventory_hostname].ansible_password | default(omit) }}" | ||
ansible_port: "{{ hostvars[inventory_hostname].ansible_port | default(omit) }}" | ||
ansible_python_interpreter: "{{ hostvars[inventory_hostname].ansible_python_interpreter | default(omit) }}" | ||
ansible_user: "{{ hostvars[inventory_hostname].ansible_user | default(omit) }}" | ||
loop: | ||
- {name: issue-1066-host-hkc-false, host_key_checking: false} | ||
- {name: issue-1066-host-hkc-true, host_key_checking: true} | ||
- {name: issue-1066-host-hskc-false, host_ssh_key_checking: false} | ||
- {name: issue-1066-host-hskc-true, host_ssh_key_checking: true} | ||
delegate_to: localhost | ||
tags: | ||
- issue_1066 | ||
|
||
- name: regression/issue_1066__add_host__host_key_checking.yml | ||
hosts: issue-1066-host-* | ||
gather_facts: false | ||
become: false | ||
serial: 1 | ||
tasks: | ||
- meta: reset_connection | ||
|
||
# The host key might be in ~/.ssh/known_hosts. If it's removed then no | ||
# problem - test-targets hosts have host_key_checking=false. | ||
- name: Remove existing host keys | ||
known_hosts: | ||
name: "{{ ansible_host }}" | ||
state: absent | ||
delegate_to: localhost | ||
|
||
- name: Ping dynamically added hosts | ||
ping: | ||
ignore_errors: true | ||
ignore_unreachable: true | ||
register: issue_1066_ping | ||
|
||
- debug: | ||
var: issue_1066_ping | ||
|
||
- name: Confirm dynamically added hosts are/are not reachable | ||
vars: | ||
expected: | ||
issue-1066-host-hkc-false: {} | ||
issue-1066-host-hkc-true: {unreachable: true} | ||
issue-1066-host-hskc-false: {} | ||
issue-1066-host-hskc-true: {unreachable: true} | ||
assert: | ||
that: | ||
- issue_1066_ping.unreachable is defined == expected[inventory_hostname].unreachable is defined | ||
- issue_1066_ping.unreachable | default(42) == expected[inventory_hostname].unreachable | default(42) | ||
# ansible_host_key_checking don't work on Vanilla Ansible 2.10, even for | ||
# static inventory hosts (ansible/ansible#49254, ansible/ansible#73708). | ||
when: | ||
- ansible_version.full is version('2.11', '>=', strict=True) | ||
or is_mitogen | ||
tags: | ||
- issue_1066 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters