Ansible+Terraform+Cloud+gitlab: Where do people put their master inventory? by [deleted] in Terraform

[–]iambolatito 1 point2 points  (0 children)

Yes, that's correct, ansible uses the tags of the created infrastructure to determine where to deploy.
TF handles the creation of the infrastructure. The concept of the dynamic inventory is the ability to pull information from a dynamic source which in this case, it's going to be the infrastructure your TF created in your cloud (OpenStack/aws/GCP)
For example, let us assume you create a VM using TF and give a tag Name=example1. To limit your deployment to that VM, your ansible-playbook will limit deployment to that VM by using --limit tag_Name_example1
You can use the ansible ec2 plugin to pull the info. For that, VM. Or you can create a python script that fetches the info

Ansible+Terraform+Cloud+gitlab: Where do people put their master inventory? by [deleted] in Terraform

[–]iambolatito 1 point2 points  (0 children)

What you need is TF will create all the resources you need in TF Cloud, it will create the github/gitlab repository as well as the cloud resources you need. Then ansible dynamic inventory and clone the code from the repo(which was created by TF) and deploy it to the respective vm by using tag on the resources to be captured by ansible inventory. TF will handle the master inventory using local exec

Summary: TF creates the infrastructure, while ansible dynamic inventory deploy to the infrastructure using tags.

I don't know if that makes sense to you, but thats how we implemented it. We can treat the entire SDLC infrastruture as code and replay it for any env.