Skip to content

Commit

Permalink
tests: Regression test for add_host with host_key_checking
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed May 3, 2024
1 parent 0f34e25 commit e3e73c5
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .ci/ansible_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def pause_if_interactive():
"ansible_python_interpreter=%(python_path)s "
"ansible_user=mitogen__has_sudo_nopw "
"ansible_password=has_sudo_nopw_password"
" ansible_host_key_checking=false"
" ansible_ssh_host_key_checking=false"
"\n"
% container
for container in containers
Expand Down
3 changes: 0 additions & 3 deletions tests/ansible/ansible.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ no_target_syslog = True
# Required by integration/ssh/timeouts.yml
timeout = 30

# On Travis, paramiko check fails due to host key checking enabled.
host_key_checking = False

[inventory]
any_unparsed_is_failed = true
host_pattern_mismatch = error
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/hosts/default.hosts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# fixed ansible.cfg remote_user setting to test against.
# FIXME Hardcoded by replacement in some CI runs https://github.com/mitogen-hq/mitogen/issues/1022
# and os.environ['USER'] is not populated on Azure macOS runners.
target ansible_host=localhost ansible_user="{{ lookup('pipe', 'whoami') }}"
target ansible_host=localhost ansible_user="{{ lookup('pipe', 'whoami') }}" ansible_host_key_checking=false ansible_ssh_host_key_checking=false

[test-targets]
target
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/regression/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
- import_playbook: issue_655__wait_for_connection_error.yml
- import_playbook: issue_776__load_plugins_called_twice.yml
- import_playbook: issue_952__ask_become_pass.yml
- import_playbook: issue_1066__add_host__host_key_checking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- name: regression/issue_1066__add_host__host_key_checking.yml
hosts: test-targets[0]
gather_facts: false
become: false
vars:
issue_1066_ansible_host: "{{ hostvars[groups['test-targets'][0]].ansible_host }}"
tasks:
# The host key might be in ~/.ssh/known_hosts. If it's removed then no
# problem - test-targets hosts have host_key_checking=false.
# See also:
# - hosts/group_vars/test-targets.yml
- name: Remove existing host keys
known_hosts:
name: "{{ issue_1066_ansible_host }}"
state: absent
delegate_to: localhost

- name: Add host dynamically
add_host:
name: issue-1066-host
ansible_host_key_checking: false
ansible_host: "{{ issue_1066_ansible_host }}"
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
tasks:
- name: Confirm new host can be reached
ping:
tags:
- issue_1066
1 change: 1 addition & 0 deletions tests/ansible/setup/report_controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- $(groups): "{{ lookup('pipe', 'groups') }}"
- $(pwd): "{{ lookup('pipe', 'pwd') }}"
- $(whoami): "{{ lookup('pipe', 'whoami') }}"
- ansible_inventory_sources: "{{ ansible_inventory_sources | default('<unset>') }}"
- ansible_run_tags: "{{ ansible_run_tags | default('<unset>') }}"
- ansible_playbook_python: "{{ ansible_playbook_python | default('<unset>') }}"
- ansible_skip_tags: "{{ ansible_skip_tags | default('<unset>') }}"
Expand Down

0 comments on commit e3e73c5

Please sign in to comment.