tfvars2facts
Tfvars2facts (Ansible Role)
This Ansible role translates the Terraform tfvrs file to Ansible Local Facts. The result is saved on the remote host(s) in /etc/ansib.e/facts.d/ directory as JSON file.
You can query the tfvars variables in Ansible by following syntax {{ ansible_local['tfvars']['my_variable'] }}
.
Note:
Since the Ansible variable names can not contain the dash sign, the dash sign(s) will be replaced by underscore.
For example my-var-1
will be my_var_1
.
Requirements
Ansible 2.8+
Role must run in privileged mode (
become: yes
)
Role Variables
This is a copy from defaults/main.yml
# Path to Ansible local facts
local_facts_path: /etc/ansible/facts.d
# Local facts file name. If changed for example to "different_file.facts",
# also the key will be {{ ansible_local['different_file']['some_variable'] }}
local_facts_file: tfvars.fact
# Enable if used with DT Pan-Net ALiEn (Application Lifecycle Engine)
ALiEn: false
# Path to Terraform variables file
# (ommited if variable ALiEn is true)
tfvars_path: files
# Terraform variables file name
tfvars_file: vars.tfvars
# Reload the Ansible facts after local facts are created
reload_facts: false
Example Playbook
In this example the role will translate Terraform variables in files/vars.tfvars
and will upload it as an Ansible facts file to the remote hosts.
The role will also reload the Ansible Facts, so the new facts will be ready 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/ansible-tfvars2facts