Skip to content

Commit edc6e8a

Browse files
dguidoclaude
andcommitted
Fix template variable and undefined job variable bugs
- Fix client.conf.j2 to use `item` instead of `item.1` to match modern loop syntax (loop with index_var instead of with_indexed_items) - Fix server.yml _vpn_jobs to use `| default({})` for job variables that may be undefined when running with tags (e.g., IPsec-only) - Update test_template_rendering.py to pass item as string instead of tuple, matching the new loop behavior Fixes CI failures from PR #14891 that were correctly identified by the Claude Code bot review. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ff7400d commit edc6e8a

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[Interface]
2-
PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + item.1) }}
2+
PrivateKey = {{ lookup('file', wireguard_pki_path + '/private/' + item) }}
33
Address = {{ wireguard_client_ip }}
44
DNS = {{ wireguard_dns_servers }}
55
{% if reduce_mtu | int > 0 %}MTU = {{ 1420 - reduce_mtu | int }}
66
{% endif %}
77

88
[Peer]
99
PublicKey = {{ lookup('file', wireguard_pki_path + '/public/' + IP_subject_alt_name) }}
10-
PresharedKey = {{ lookup('file', wireguard_pki_path + '/preshared/' + item.1) }}
10+
PresharedKey = {{ lookup('file', wireguard_pki_path + '/preshared/' + item) }}
1111
AllowedIPs = 0.0.0.0/0,::/0
1212
Endpoint = {% if ':' in IP_subject_alt_name %}[{{ IP_subject_alt_name }}]:{{ wireguard_port }}{% else %}{{ IP_subject_alt_name }}:{{ wireguard_port }}{% endif %}
1313
{{ 'PersistentKeepalive = ' + wireguard_PersistentKeepalive | string if wireguard_PersistentKeepalive > 0 else '' }}

server.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@
8888
- name: Build async job list
8989
set_fact:
9090
_vpn_jobs:
91-
- {name: dns, job: "{{ dns_job }}", tag: dns}
92-
- {name: wireguard, job: "{{ wireguard_job }}", tag: wireguard}
93-
- {name: strongswan, job: "{{ strongswan_job }}", tag: ipsec}
94-
- {name: ssh_tunneling, job: "{{ ssh_tunneling_job }}", tag: ssh_tunneling}
91+
- {name: dns, job: "{{ dns_job | default({}) }}"}
92+
- {name: wireguard, job: "{{ wireguard_job | default({}) }}"}
93+
- {name: strongswan, job: "{{ strongswan_job | default({}) }}"}
94+
- {name: ssh_tunneling, job: "{{ ssh_tunneling_job | default({}) }}"}
9595

9696
- name: Wait for VPN services to complete
9797
async_status:

tests/unit/test_template_rendering.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,9 @@ def test_critical_templates():
131131
template = env.get_template(template_name)
132132

133133
# Add item context for templates that use loops
134+
# With modern loop syntax, item is the username string directly
134135
if "client" in template_name:
135-
test_vars["item"] = ("test-user", "test-user")
136+
test_vars["item"] = "test-user"
136137

137138
# Try to render
138139
output = template.render(**test_vars)
@@ -211,7 +212,8 @@ def test_wireguard_ipv6_endpoints():
211212
try:
212213
# Set up test variables
213214
test_vars = {**base_vars, **test_case}
214-
test_vars["item"] = ("test-user", "test-user")
215+
# With modern loop syntax, item is the username string directly
216+
test_vars["item"] = "test-user"
215217

216218
# Render template
217219
env = Environment(loader=FileSystemLoader("roles/wireguard/templates"), undefined=StrictUndefined)

0 commit comments

Comments
 (0)