40 lines
1.2 KiB
YAML
40 lines
1.2 KiB
YAML
---
|
|
- name: Provision DigitalOcean cloud
|
|
hosts: localhost
|
|
vars:
|
|
terraform_backend: "postgres://{{ skylab_tfstate_backend.username }}:{{ skylab_tfstate_backend.password }}@{{ skylab_tfstate_backend.hostname }}:{{ skylab_tfstate_backend.port }}/{{ skylab_tfstate_backend.schema }}"
|
|
tasks:
|
|
- name: Deploy terraform config
|
|
block:
|
|
- name: Create temp plan file
|
|
changed_when: false
|
|
ansible.builtin.tempfile:
|
|
state: file
|
|
prefix: skylab
|
|
suffix: tfplan
|
|
register: _tfplan_tempfile
|
|
|
|
- name: Initialize terraform backend and generate plan file
|
|
community.general.terraform:
|
|
state: planned
|
|
project_path: terraform/
|
|
backend_config:
|
|
conn_str: "{{ terraform_backend }}"
|
|
force_init: true
|
|
init_reconfigure: true
|
|
plan_file: "{{ _tfplan_tempfile.path }}"
|
|
|
|
- name: Apply terraform plan
|
|
community.general.terraform:
|
|
state: present
|
|
project_path: terraform/
|
|
backend_config:
|
|
conn_str: "{{ terraform_backend }}"
|
|
plan_file: "{{ _tfplan_tempfile.path }}"
|
|
always:
|
|
- name: Remove temp plan file
|
|
changed_when: false
|
|
ansible.builtin.file:
|
|
path: "{{ _tfplan_tempfile.path }}"
|
|
state: absent
|