60 lines
2.2 KiB
YAML
60 lines
2.2 KiB
YAML
---
|
|
# TODO: This doesn't have any real idempotency. Can't compare current and desired states.
|
|
- name: Provision Database
|
|
hosts: prod:&appwrite
|
|
gather_facts: false
|
|
module_defaults:
|
|
ansible.builtin.uri:
|
|
body_format: json
|
|
headers:
|
|
X-Appwrite-Response-Format: '{{ appwrite_response_format }}'
|
|
X-Appwrite-Project: '{{ appwrite_project }}'
|
|
X-Appwrite-Key: '{{ appwrite_api_key }}'
|
|
return_content: true
|
|
tasks:
|
|
- name: Use Appwrite REST API to create new database
|
|
ansible.builtin.uri:
|
|
url: "{{ appwrite_api_uri }}/databases"
|
|
method: POST
|
|
body:
|
|
databaseId: "{{ bab_database.id }}"
|
|
name: "{{ bab_database.name }}"
|
|
enabled: "{{ bab_database.enabled }}"
|
|
status_code: [201, 409]
|
|
register: appwrite_api_result
|
|
delegate_to: localhost
|
|
|
|
- name: Create Collections
|
|
ansible.builtin.uri:
|
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/"
|
|
method: POST
|
|
body:
|
|
collectionId: "{{ item.id }}"
|
|
name: "{{ item.name }}"
|
|
permissions: "{{ item.permissions }}"
|
|
status_code: [201, 409]
|
|
register: appwrite_api_result
|
|
loop: '{{ bab_database.collections }}'
|
|
delegate_to: localhost
|
|
|
|
# - name: Create Attributes
|
|
# ansible.builtin.debug:
|
|
# msg: "{{ lookup('ansible.builtin.template', 'appwrite_attribute_template.json.j2') }}"
|
|
# register: appwrite_api_result
|
|
# loop: "{{ bab_database.collections | subelements('attributes', skip_missing=True) }}"
|
|
# # delegate_to: localhost
|
|
|
|
- name: Create Attributes
|
|
ansible.builtin.uri:
|
|
url: "{{ appwrite_api_uri }}/databases/{{ bab_database.id }}/collections/{{ item[0].id }}/attributes/{{ (item[1].format is defined and item[1].format != '' ) |ternary(item[1].format, item[1].type) }}"
|
|
method: POST
|
|
body: "{{ lookup('ansible.builtin.template', 'appwrite_attribute_template.json.j2') }}"
|
|
status_code: [202, 409]
|
|
register: appwrite_api_result
|
|
loop: "{{ bab_database.collections | subelements('attributes', skip_missing=True) }}"
|
|
delegate_to: localhost
|
|
|
|
# - name: Display response
|
|
# ansible.builtin.debug:
|
|
# var: appwrite_api_result
|