monolithprojects.tfvars2facts
Tfvars2facts (Ansible Role)
This Ansible role converts Terraform tfvars files into Ansible Local Facts. The converted facts are stored on the remote host(s) in the /etc/ansible/facts.d/
directory as a JSON file.
You can access the tfvars variables in Ansible using the syntax {{ ansible_local['tfvars']['my_variable'] }}
.
Note:
Since Ansible variable names cannot have dashes, any dashes will be replaced with underscores. For example, my-var-1
will become my_var_1
.
Requirements
Ansible 2.8 or higher
The role needs to run in privileged mode (
become: yes
)
Role Variables
These are the default settings found in defaults/main.yml
# Path to Ansible local facts
local_facts_path: /etc/ansible/facts.d
# Name of the local facts file. If renamed, for example to "different_file.facts",
# the key will change to {{ ansible_local['different_file']['some_variable'] }}
local_facts_file: tfvars.fact
# Set to true if used with DT Pan-Net ALiEn (Application Lifecycle Engine)
ALiEn: false
# Path to the Terraform variables file
# (omit if ALiEn is true)
tfvars_path: files
# Name of the Terraform variables file
tfvars_file: vars.tfvars
# Reload the Ansible facts after the local facts are created
reload_facts: false
Example Playbook
In this example, the role will convert the Terraform variables in files/vars.tfvars
and will upload them as an Ansible facts file to the remote hosts. It will also reload the Ansible Facts, making the new facts available for the next role/post-task.
---
- name: Simple Example
hosts: all
become: yes
vars:
reload_facts: yes
roles:
- role: ansible-tfvars2facts
License
MIT
Author Information
Created in 2020 by Michal Muransky/DT Pan-Net
Translate the Terraform tfvars to the Ansible local facts.
ansible-galaxy install monolithprojects.tfvars2facts