Skip to content

Commit cb4620d

Browse files
dguidoclaude
andcommitted
Fix Ansible 12 double-templating and Jinja2 spacing issues
This PR fixes critical deployment issues and improves code consistency for Ansible 12 compatibility. ## Fixed Issues ### 1. Double-templating bug (Issue #14835) Fixed 7 instances of invalid double-templating that breaks deployments: - Changed `{{ lookup('file', '{{ var }}') }}` to `{{ lookup('file', var) }}` - Affects Azure, DigitalOcean, GCE, Linode, and IPsec configurations - Added comprehensive test to prevent regression ### 2. Jinja2 spacing inconsistencies Fixed 33+ spacing issues for better code quality: - Removed spaces between Jinja2 blocks: `}} {%` → `}}{%` - Fixed operator spacing: `int -1` → `int - 1` - Fixed filter spacing: `|b64encode` → `| b64encode` - Consolidated multiline expressions to single lines ### 3. Test suite improvements Enhanced boolean type checking test to be more targeted: - Excludes external dependencies and CloudFormation templates - Only tests Algo's actual codebase - Verified with mutation testing - Added comprehensive documentation ## Testing - All 87 unit tests pass - 0 Jinja2 spacing issues remaining (verified by ansible-lint) - Ansible syntax checks pass for all playbooks - Mutation testing confirms tests catch real issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 72900d3 commit cb4620d

File tree

24 files changed

+306
-187
lines changed

24 files changed

+306
-187
lines changed

files/cloud-init/base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ users:
3030
shell: /bin/bash
3131
lock_passwd: true
3232
ssh_authorized_keys:
33-
- "{{ lookup('file', '{{ SSH_keys.public }}') }}"
33+
- "{{ lookup('file', SSH_keys.public) }}"
3434

3535
write_files:
3636
- path: /etc/ssh/sshd_config

input.yml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,22 @@
109109
- name: Set facts based on the input
110110
set_fact:
111111
algo_server_name: >-
112-
{% if server_name is defined %}{% set _server = server_name %}
113-
{%- elif _algo_server_name.user_input is defined and _algo_server_name.user_input | length > 0 -%}
112+
{% if server_name is defined %}{% set _server = server_name %}{%- elif _algo_server_name.user_input is defined and _algo_server_name.user_input | length > 0 -%}
114113
{%- set _server = _algo_server_name.user_input -%}
115114
{%- else %}{% set _server = defaults['server_name'] %}{% endif -%}
116-
{{ _server | regex_replace('(?!\.)(\W | _)', '-') }}
115+
{{ _server | regex_replace('(?!\.)(\W|_)', '-') }}
117116
algo_ondemand_cellular: >-
118-
{% if ondemand_cellular is defined %}{{ ondemand_cellular | bool }}
119-
{%- elif _ondemand_cellular.user_input is defined %}{{ booleans_map[_ondemand_cellular.user_input] | default(defaults['ondemand_cellular']) }}
120-
{%- else %}{{ false }}{% endif %}
117+
{% if ondemand_cellular is defined %}{{ ondemand_cellular | bool }}{%- elif _ondemand_cellular.user_input is defined %}{{ booleans_map[_ondemand_cellular.user_input] | default(defaults['ondemand_cellular']) }}{%- else %}{{ false }}{% endif %}
121118
algo_ondemand_wifi: >-
122-
{% if ondemand_wifi is defined %}{{ ondemand_wifi | bool }}
123-
{%- elif _ondemand_wifi.user_input is defined %}{{ booleans_map[_ondemand_wifi.user_input] | default(defaults['ondemand_wifi']) }}
124-
{%- else %}{{ false }}{% endif %}
119+
{% if ondemand_wifi is defined %}{{ ondemand_wifi | bool }}{%- elif _ondemand_wifi.user_input is defined %}{{ booleans_map[_ondemand_wifi.user_input] | default(defaults['ondemand_wifi']) }}{%- else %}{{ false }}{% endif %}
125120
algo_ondemand_wifi_exclude: >-
126-
{% if ondemand_wifi_exclude is defined %}{{ ondemand_wifi_exclude | b64encode }}
127-
{%- elif _ondemand_wifi_exclude.user_input is defined and _ondemand_wifi_exclude.user_input | length > 0 -%}
128-
{{ _ondemand_wifi_exclude.user_input | b64encode }}
129-
{%- else %}{{ '_null' | b64encode }}{% endif %}
121+
{% if ondemand_wifi_exclude is defined %}{{ ondemand_wifi_exclude | b64encode }}{%- elif _ondemand_wifi_exclude.user_input is defined and _ondemand_wifi_exclude.user_input | length > 0 -%}
122+
{{ _ondemand_wifi_exclude.user_input | b64encode }}{%- else %}{{ '_null' | b64encode }}{% endif %}
130123
algo_dns_adblocking: >-
131-
{% if dns_adblocking is defined %}{{ dns_adblocking | bool }}
132-
{%- elif _dns_adblocking.user_input is defined %}{{ booleans_map[_dns_adblocking.user_input] | default(defaults['dns_adblocking']) }}
133-
{%- else %}{{ false }}{% endif %}
124+
{% if dns_adblocking is defined %}{{ dns_adblocking | bool }}{%- elif _dns_adblocking.user_input is defined %}{{ booleans_map[_dns_adblocking.user_input] | default(defaults['dns_adblocking']) }}{%- else %}{{ false }}{% endif %}
134125
algo_ssh_tunneling: >-
135-
{% if ssh_tunneling is defined %}{{ ssh_tunneling | bool }}
136-
{%- elif _ssh_tunneling.user_input is defined %}{{ booleans_map[_ssh_tunneling.user_input] | default(defaults['ssh_tunneling']) }}
137-
{%- else %}{{ false }}{% endif %}
126+
{% if ssh_tunneling is defined %}{{ ssh_tunneling | bool }}{%- elif _ssh_tunneling.user_input is defined %}{{ booleans_map[_ssh_tunneling.user_input] | default(defaults['ssh_tunneling']) }}{%- else %}{{ false }}{% endif %}
138127
algo_store_pki: >-
139-
{% if ipsec_enabled %}{%- if store_pki is defined %}{{ store_pki | bool }}
140-
{%- elif _store_pki.user_input is defined %}{{ booleans_map[_store_pki.user_input] | default(defaults['store_pki']) }}
141-
{%- else %}{{ false }}{% endif %}{% endif %}
128+
{% if ipsec_enabled %}{%- if store_pki is defined %}{{ store_pki | bool }}{%- elif _store_pki.user_input is defined %}{{ booleans_map[_store_pki.user_input] | default(defaults['store_pki']) }}{%- else %}{{ false }}{% endif %}{% endif %}
142129
rescue:
143130
- include_tasks: playbooks/rescue.yml

roles/cloud-azure/tasks/main.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
- set_fact:
99
algo_region: >-
10-
{% if region is defined %}{{ region }}
11-
{%- elif _algo_region.user_input %}{{ azure_regions[_algo_region.user_input | int -1 ]['name'] }}
12-
{%- else %}{{ azure_regions[default_region | int - 1]['name'] }}{% endif %}
10+
{% if region is defined %}{{ region }}{%- elif _algo_region.user_input %}{{ azure_regions[_algo_region.user_input | int - 1]['name'] }}{%- else %}{{ azure_regions[default_region | int - 1]['name'] }}{% endif %}
1311
1412
- name: Create AlgoVPN Server
1513
azure_rm_deployment:
@@ -24,7 +22,7 @@
2422
location: "{{ algo_region }}"
2523
parameters:
2624
sshKeyData:
27-
value: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
25+
value: "{{ lookup('file', SSH_keys.public) }}"
2826
WireGuardPort:
2927
value: "{{ wireguard_port }}"
3028
vmSize:

roles/cloud-azure/tasks/prompts.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
- name: Set the default region
1111
set_fact:
1212
default_region: >-
13-
{% for r in azure_regions %}
14-
{%- if r['name'] == "eastus" %}{{ loop.index }}{% endif %}
15-
{%- endfor %}
13+
{% for r in azure_regions %}{%- if r['name'] == "eastus" %}{{ loop.index }}{% endif %}{%- endfor %}
1614
1715
- pause:
1816
prompt: |

roles/cloud-cloudstack/tasks/main.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
- block:
99
- set_fact:
1010
algo_region: >-
11-
{% if region is defined %}{{ region }}
12-
{%- elif _algo_region.user_input is defined and _algo_region.user_input | length > 0 %}{{ cs_zones[_algo_region.user_input | int -1 ]['name'] }}
13-
{%- else %}{{ cs_zones[default_zone | int - 1]['name'] }}{% endif %}
11+
{%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input is defined and _algo_region.user_input | length > 0 -%}{{ cs_zones[_algo_region.user_input | int - 1]['name'] }}{%- else -%}{{ cs_zones[default_zone | int - 1]['name'] }}{%- endif -%}
1412
1513
- name: Security group created
1614
cs_securitygroup:

roles/cloud-cloudstack/tasks/prompts.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
- name: Set the default zone
5555
set_fact:
5656
default_zone: >-
57-
{% for z in cs_zones %}
58-
{%- if z['name'] == "ch-gva-2" %}{{ loop.index }}{% endif %}
57+
{%- for z in cs_zones -%}
58+
{%- if z['name'] == "ch-gva-2" %}{{ loop.index }}{% endif -%}
5959
{%- endfor %}
6060
6161
- pause:

roles/cloud-digitalocean/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
digital_ocean_sshkey:
77
oauth_token: "{{ algo_do_token }}"
88
name: "{{ SSH_keys.comment }}"
9-
ssh_pub_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
9+
ssh_pub_key: "{{ lookup('file', SSH_keys.public) }}"
1010
register: do_ssh_key
1111

1212
- name: Creating a droplet...

roles/cloud-digitalocean/tasks/prompts.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@
3232
- name: Set default region
3333
set_fact:
3434
default_region: >-
35-
{% for r in do_regions %}
36-
{%- if r['slug'] == "nyc3" %}{{ loop.index }}{% endif %}
37-
{%- endfor %}
35+
{% for r in do_regions %}{%- if r['slug'] == "nyc3" %}{{ loop.index }}{% endif %}{%- endfor %}
3836
3937
- pause:
4038
prompt: |
@@ -51,6 +49,4 @@
5149
- name: Set additional facts
5250
set_fact:
5351
algo_do_region: >-
54-
{% if region is defined %}{{ region }}
55-
{%- elif _algo_region.user_input %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }}
56-
{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}
52+
{% if region is defined %}{{ region }}{%- elif _algo_region.user_input %}{{ do_regions[_algo_region.user_input | int - 1]['slug'] }}{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}

roles/cloud-ec2/tasks/prompts.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@
8282
- name: Set the default region
8383
set_fact:
8484
default_region: >-
85-
{% for r in aws_regions %}
86-
{%- if r['region_name'] == "us-east-1" %}{{ loop.index }}{% endif %}
85+
{%- for r in aws_regions -%}
86+
{%- if r['region_name'] == "us-east-1" %}{{ loop.index }}{% endif -%}
8787
{%- endfor %}
8888
8989
- pause:
@@ -102,9 +102,7 @@
102102
- name: Set algo_region and stack_name facts
103103
set_fact:
104104
algo_region: >-
105-
{% if region is defined %}{{ region }}
106-
{%- elif _algo_region.user_input %}{{ aws_regions[_algo_region.user_input | int -1 ]['region_name'] }}
107-
{%- else %}{{ aws_regions[default_region | int - 1]['region_name'] }}{% endif %}
105+
{%- if region is defined -%}{{ region }}{%- elif _algo_region.user_input -%}{{ aws_regions[_algo_region.user_input | int - 1]['region_name'] }}{%- else -%}{{ aws_regions[default_region | int - 1]['region_name'] }}{%- endif -%}
108106
stack_name: "{{ algo_server_name | replace('.', '-') }}"
109107

110108
- block:
@@ -131,5 +129,5 @@
131129
register: _use_existing_eip
132130

133131
- set_fact:
134-
existing_eip: "{{ available_eip_addresses[_use_existing_eip.user_input | int -1 ]['allocation_id'] }}"
132+
existing_eip: "{{ available_eip_addresses[_use_existing_eip.user_input | int - 1]['allocation_id'] }}"
135133
when: cloud_providers.ec2.use_existing_eip

roles/cloud-gce/tasks/prompts.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
credentials_file_path: >-
1414
{{ gce_credentials_file | default(_gce_credentials_file.user_input|default(None)) |
1515
default(lookup('env', 'GCE_CREDENTIALS_FILE_PATH'), true) }}
16-
ssh_public_key_lookup: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
16+
ssh_public_key_lookup: "{{ lookup('file', SSH_keys.public) }}"
1717
no_log: true
1818

1919
- set_fact:
20-
credentials_file_lookup: "{{ lookup('file', '{{ credentials_file_path }}') }}"
20+
credentials_file_lookup: "{{ lookup('file', credentials_file_path) }}"
2121
no_log: true
2222

2323
- set_fact:
@@ -66,7 +66,7 @@
6666
set_fact:
6767
algo_region: >-
6868
{% if region is defined %}{{ region }}
69-
{%- elif _gce_region.user_input %}{{ gce_regions[_gce_region.user_input | int -1 ] }}
69+
{%- elif _gce_region.user_input %}{{ gce_regions[_gce_region.user_input | int - 1] }}
7070
{%- else %}{{ gce_regions[default_region | int - 1] }}{% endif %}
7171
7272
- name: Get zones

0 commit comments

Comments
 (0)