Using Ansible from other tools (Eg. Terraform)

Hey everyone!

A month ago I opened an issue regarding how the ansible-pull command assumes local connections should be used, in the context of a pull vs. push architecture. I was kindly informed there are no plans to change this, and that my desired outcome can be achieved differently. So I’m looking for suggestions regarding how.

What I’m looking for, is something that would allow me to embed an Ansible playbook run as a single command, into a provisioner block in Terraform, thereby allowing my playbook to run after the infrastructure has been stood up.

More generally speaking: I am trying to achieve what ansible-pull does, but for remote hosts. That is, I want to have a single line command, which points to an internal git repository with a playbook, to download and run said playbook, without requiring the operator to manage configuring and syncing to the git repository.

If anyone has thoughts on how this can be done, I’d greatly appreciate it.

Thank you, Philip.

Hi Philip

TBH, I don’t really see the advantage of doing anything this way, you’re just making more work for yourself.
But perhaps something like this is to your liking: https://github.com/radekg/terraform-provisioner-ansible

You can of course automate the setup of ansible-pull on each client, but you’ll need to find something to do that in the first place. Here’s my example: https://github.com/ffirg/ansible-pull

Why not just wrap the terraform + ansible-playbook work into a shell wrapper?

Regards
Phil.

Instead of using ansible-pull, you can just use ansible-playbook and
give it a play that does the git checkout (ansible-pull uses the git
module) and then executes with targets/connections as you wish.