|
| 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 |
0 commit comments