playbooks/deploy_billing_service.yml
2026-04-12 19:05:17 +08:00

88 lines
3.9 KiB
YAML

- name: Deploy billing-service
hosts: "{{ billing_service_hosts | default('billing_service') }}"
gather_facts: true
become: true
vars:
billing_service_binary_artifact: >-
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_BINARY_ARTIFACT')
| default('', true) }}
billing_service_image_ref: >-
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_IMAGE_REF')
| default('', true) }}
billing_service_exporter_base_url: >-
{{ lookup('ansible.builtin.env', 'EXPORTER_BASE_URL')
| default('http://127.0.0.1:8080', true) }}
billing_service_exporter_sources_json: >-
{{ lookup('ansible.builtin.env', 'EXPORTER_SOURCES_JSON')
| default('', true) }}
billing_service_internal_service_token: >-
{{ lookup('ansible.builtin.vars', 'INTERNAL_SERVICE_TOKEN', default=lookup('ansible.builtin.env', 'INTERNAL_SERVICE_TOKEN') | default('', true)) }}
billing_service_database_url: >-
{{ lookup('ansible.builtin.env', 'DATABASE_URL')
| default('', true) }}
billing_service_listen_addr: >-
{{ lookup('ansible.builtin.env', 'BILLING_SERVICE_LISTEN_ADDR')
| default('127.0.0.1:8081', true) }}
billing_service_collect_interval: >-
{{ lookup('ansible.builtin.env', 'COLLECT_INTERVAL')
| default('1m', true) }}
billing_service_default_region: >-
{{ lookup('ansible.builtin.env', 'DEFAULT_REGION')
| default('', true) }}
billing_service_source_revision: >-
{{ lookup('ansible.builtin.env', 'SOURCE_REVISION')
| default('billing-service-v1', true) }}
billing_service_price_per_byte: >-
{{ lookup('ansible.builtin.env', 'PRICE_PER_BYTE')
| default('0', true) }}
billing_service_initial_included_quota_bytes: >-
{{ lookup('ansible.builtin.env', 'INITIAL_INCLUDED_QUOTA_BYTES')
| default('0', true) }}
billing_service_initial_balance: >-
{{ lookup('ansible.builtin.env', 'INITIAL_BALANCE')
| default('0', true) }}
pre_tasks:
- name: Validate BILLING_SERVICE_BINARY_ARTIFACT is present
ansible.builtin.assert:
that:
- billing_service_binary_artifact | length > 0
fail_msg: "BILLING_SERVICE_BINARY_ARTIFACT must be exported before running this playbook."
success_msg: "BILLING_SERVICE_BINARY_ARTIFACT found"
- name: Validate BILLING_SERVICE_BINARY_ARTIFACT exists
ansible.builtin.stat:
path: "{{ billing_service_binary_artifact }}"
register: billing_service_binary_artifact_stat
delegate_to: localhost
become: false
run_once: true
- name: Assert BILLING_SERVICE_BINARY_ARTIFACT exists on controller
ansible.builtin.assert:
that:
- billing_service_binary_artifact_stat.stat.exists
- billing_service_binary_artifact_stat.stat.isreg
fail_msg: "BILLING_SERVICE_BINARY_ARTIFACT must point to an existing binary artifact."
success_msg: "BILLING_SERVICE_BINARY_ARTIFACT exists"
delegate_to: localhost
become: false
run_once: true
- name: Validate BILLING_SERVICE_IMAGE_REF is present
ansible.builtin.assert:
that:
- billing_service_image_ref | length > 0
fail_msg: "BILLING_SERVICE_IMAGE_REF must be exported before running this playbook."
success_msg: "BILLING_SERVICE_IMAGE_REF found"
- name: Validate DATABASE_URL is present
ansible.builtin.assert:
that:
- billing_service_database_url | length > 0
fail_msg: "DATABASE_URL must be exported before running this playbook."
success_msg: "DATABASE_URL found"
- name: Validate INTERNAL_SERVICE_TOKEN is present
ansible.builtin.assert:
that:
- billing_service_internal_service_token | length > 0
fail_msg: "INTERNAL_SERVICE_TOKEN must be exported before running this playbook."
success_msg: "INTERNAL_SERVICE_TOKEN found"
roles:
- roles/vhosts/billing-service