From 8833dc567a1a09c9d0cf8b5960e0f8e6eafc1e13 Mon Sep 17 00:00:00 2001 From: Rich Megginson Date: Tue, 5 Aug 2025 09:08:04 -0600 Subject: [PATCH] test: default wrapper should use local connection if local tests_default_wrapper.yml should use local connection for the nested test if the test is using local connection Signed-off-by: Rich Megginson --- tests/inventory.yaml.j2 | 13 +++++++++---- tests/tests_default_wrapper.yml | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) 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: