ansible-collection-interweb-mz/examples/vps.yml
2026-11-28 15:28:03 +02:00

36 lines
1.1 KiB
YAML

---
# Buy a VPS only when the account has none with that plan, then keep it running.
# With a sandbox_ key the purchase is simulated.
- name: VPS
hosts: localhost
gather_facts: false
vars:
plan_name: VPS1
billing_cycle: monthly
tasks:
- name: Servers we already have
interweb_mz.cloud.vps_info:
register: current
- name: Plans for sale
interweb_mz.cloud.catalog_info:
what: products
kind: vps
register: plans
- name: Buy one when there is none with that plan
interweb_mz.cloud.vps:
product_id: "{{ (plans.products | selectattr('name', 'equalto', plan_name) | first).id }}"
billing_cycle: "{{ billing_cycle }}"
idempotency_key: "web-{{ plan_name | lower }}-1"
state: running
register: bought
when: current.servers | selectattr('product', 'search', plan_name) | list | length == 0
- name: Keep every server running
interweb_mz.cloud.vps:
server_id: "{{ item.id }}"
state: running
loop: "{{ current.servers }}"
loop_control:
label: "{{ item.name }}"