diff --git a/tests/inventory.yaml.j2 b/tests/inventory.yaml.j2 index c3dffa2..7b46372 100644 --- a/tests/inventory.yaml.j2 +++ b/tests/inventory.yaml.j2 @@ -1,11 +1,16 @@ all: hosts: {{ inventory_hostname }}: -{% for key in ["ansible_all_ipv4_addresses", "ansible_all_ipv6_addresses", +{% if __ansible_connection == "local" %} + ansible_connection: local + ansible_host: localhost +{% else %} +{% for key in ["ansible_all_ipv4_addresses", "ansible_all_ipv6_addresses", "ansible_default_ipv4", "ansible_default_ipv6", "ansible_host", "ansible_port", "ansible_ssh_common_args", "ansible_ssh_private_key_file","ansible_user"] %} -{% if key in hostvars[inventory_hostname] %} +{% if key in hostvars[inventory_hostname] %} {{ key }}: {{ hostvars[inventory_hostname][key] }} -{% endif %} -{% endfor %} +{% endif %} +{% endfor %} +{% endif %} diff --git a/tests/tests_default_wrapper.yml b/tests/tests_default_wrapper.yml index 48be3e7..2b5d394 100644 --- a/tests/tests_default_wrapper.yml +++ b/tests/tests_default_wrapper.yml @@ -5,6 +5,10 @@ tags: - tests::booted tasks: + - name: Save connection method + set_fact: + __ansible_connection: "{{ ansible_connection }}" + - name: Run test block: - name: Create temporary file @@ -12,6 +16,7 @@ state: file suffix: .yaml register: tempinventory + delegate_to: localhost - name: Create static inventory from hostvars template: