36 lines
1.1 KiB
YAML
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
|
|
mozout.cloud.vps_info:
|
|
register: current
|
|
|
|
- name: Plans for sale
|
|
mozout.cloud.catalog_info:
|
|
what: products
|
|
kind: vps
|
|
register: plans
|
|
|
|
- name: Buy one when there is none with that plan
|
|
mozout.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
|
|
mozout.cloud.vps:
|
|
server_id: "{{ item.id }}"
|
|
state: running
|
|
loop: "{{ current.servers }}"
|
|
loop_control:
|
|
label: "{{ item.name }}"
|