bob/roles/infrastructure/tasks/main.yaml
Marty Oehme 40b687a3f3
feat: Create skeleton for terraform provisioning role
The terraform module does not expect its file contents (project_path) in
the 'files/' folder like the core roles, instead looking for it relative
to the _invocation_ pwd.
So, for now it just resides in the root level of the repository and may
be moved from there to wherever it is more pertinent.

Additionally, we check for the existence of the OpenTofu binary (tofu),
and prefer that if it exists. Otherwise we fall back to the Terraform
binary.
2025-11-28 14:19:26 +01:00

26 lines
636 B
YAML

---
# role currently only works with opentofu
# Either manually extend to both or just leave out test?
- name: Check if tofu is installed
vars:
terraform_bin: tofu
ansible.builtin.command:
argv:
- which
- "{{ terraform_bin|quote }}"
check_mode: false # run even in check mode
tags: debug
register: tofu_installed
failed_when: false
changed_when: false
- name: Run terraform
community.general.terraform:
binary_path: "{{ (tofu_installed.rc in [ 0 ]) | ternary('tofu', 'terraform') }}"
project_path: "tofu/"
state: present
register: output
- name: Debug output
debug:
var: output