https://github.com/monolithprojects/ansible-tfvars2facts
This role will help you to use the Terraform variables (tfvars) as Ansible local facts.
https://github.com/monolithprojects/ansible-tfvars2facts
Last synced: 8 months ago
JSON representation
This role will help you to use the Terraform variables (tfvars) as Ansible local facts.
- Host: GitHub
- URL: https://github.com/monolithprojects/ansible-tfvars2facts
- Owner: MonolithProjects
- License: mit
- Created: 2019-12-29T20:45:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-09T11:02:43.000Z (almost 6 years ago)
- Last Synced: 2025-03-16T20:21:26.902Z (over 1 year ago)
- Language: Python
- Homepage: https://galaxy.ansible.com/monolithprojects/tfvars2facts
- Size: 282 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tfvars2facts (Ansible Role)
[](https://galaxy.ansible.com/monolithprojects/tfvars2facts)
[](https://galaxy.ansible.com/monolithprojects/tfvars2facts)
[](https://galaxy.ansible.com/monolithprojects/tfvars2facts)
[](https://github.com/MonolithProjects/ansible-tfvars2facts/actions)
[](https://github.com/MonolithProjects/ansible-tfvars2facts/blob/master/LICENSE)
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`
```yaml
# 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.
```yaml
---
- 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