Files
algo/roles/cloud-openstack/tasks/main.yml
cfda275a20 Simplify codebase: modernize loops, split templates, improve CI (#14891)
* Simplify codebase: remove dead venv files, consolidate loops, modernize patterns

- Delete 8 empty venv.yml files that were remnants of pyproject.toml migration
- Remove corresponding import_tasks references from cloud provider main.yml files
- Consolidate server.yml async polling from 4 copy-paste blocks to 1 loop
- Wrap sequential VPN service imports in a block with single when condition
- Replace deprecated with_indexed_items with modern loop/loop_control syntax

These changes reduce maintenance burden by:
- Eliminating 8 files that served no purpose
- Reducing server.yml by ~20 lines while improving readability
- Removing Ansible deprecation warnings for with_indexed_items
- Making the parallel/sequential execution paths easier to maintain

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* 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 <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-11-28 04:57:06 -05:00

82 lines
2.7 KiB
YAML

---
- fail:
msg: >-
OpenStack credentials are not set. Download it from the OpenStack dashboard->Compute->API Access
and source it in the shell (eg: source /tmp/dhc-openrc.sh)
when: lookup('env', 'OS_AUTH_URL')|length <= 0
- name: Security group created
openstack.cloud.security_group:
state: "{{ state | default('present') }}"
name: "{{ algo_server_name }}-security_group"
description: AlgoVPN security group
register: os_security_group
- name: Security rules created
openstack.cloud.security_group_rule:
state: "{{ state | default('present') }}"
security_group: "{{ os_security_group.id }}"
protocol: "{{ item.proto }}"
port_range_min: "{{ item.port_min }}"
port_range_max: "{{ item.port_max }}"
remote_ip_prefix: "{{ item.range }}"
loop:
- { proto: tcp, port_min: "{{ ssh_port }}", port_max: "{{ ssh_port }}", range: 0.0.0.0/0 }
- { proto: icmp, port_min: -1, port_max: -1, range: 0.0.0.0/0 }
- { proto: udp, port_min: 4500, port_max: 4500, range: 0.0.0.0/0 }
- { proto: udp, port_min: 500, port_max: 500, range: 0.0.0.0/0 }
- { proto: udp, port_min: "{{ wireguard_port }}", port_max: "{{ wireguard_port }}", range: 0.0.0.0/0 }
- name: Gather facts about flavors
openstack.cloud.compute_flavor_info:
ram: "{{ cloud_providers.openstack.flavor_ram }}"
register: os_flavor
- name: Gather facts about images
openstack.cloud.image_info:
register: os_image
- name: Set image as a fact
set_fact:
image_id: "{{ item.id }}"
loop: "{{ os_image.openstack_image }}"
when:
- item.name == cloud_providers.openstack.image
- item.status == "active"
- name: Gather facts about public networks
openstack.cloud.networks_info:
register: os_network
- name: Set the network as a fact
set_fact:
public_network_id: "{{ item.id }}"
when:
- item['router:external']|default(omit)
- item['admin_state_up']|default(omit)
- item['status'] == 'ACTIVE'
loop: "{{ os_network.openstack_networks }}"
- name: Set facts
set_fact:
flavor_id: "{{ (os_flavor.openstack_flavors | sort(attribute='ram'))[0]['id'] }}"
security_group_name: "{{ os_security_group['secgroup']['name'] }}"
- name: Server created
openstack.cloud.server:
state: "{{ state | default('present') }}"
name: "{{ algo_server_name }}"
image: "{{ image_id }}"
flavor: "{{ flavor_id }}"
security_groups: "{{ security_group_name }}"
userdata: "{{ lookup('template', 'files/cloud-init/base.yml') }}"
nics:
- net-id: "{{ public_network_id }}"
register: os_server
- set_fact:
cloud_instance_ip: "{{ os_server['openstack']['public_v4'] }}"
ansible_ssh_user: algo
ansible_ssh_port: "{{ ssh_port }}"
cloudinit: true