Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Ansible provisioner #2661

Closed
lukehoersten opened this issue Jul 8, 2015 · 151 comments
Closed

Create Ansible provisioner #2661

lukehoersten opened this issue Jul 8, 2015 · 151 comments

Comments

@lukehoersten
Copy link

I'd like to use Terraform to build infrastructure then configure it with Ansible, similar to the Chef provisioner.

@donovanmuller
Copy link

+1

@martineg
Copy link

+1
(is https://github.com/adammck/terraform-inventory an alternative?)

@lukehoersten
Copy link
Author

terraform-inventory just isn't as clean as the Terraform Chef provisioner and hopefully what a true Ansible provisioner could be.

@tony612
Copy link

tony612 commented Jul 15, 2015

👍

@IanVS
Copy link

IanVS commented Jul 21, 2015

Honest question: would there be a benefit to having a built-in Ansible provisioner over-and-above just using local-exec and using the Ansible cli?

@donovanmuller
Copy link

@IanVS That is the route I followed initially but Terraform seems to buffer stdout, so once you kick off your Ansible plays you don't see anything until your play is done or has been running enough until the buffer flushes.

I'm hoping support for Ansible would hopefully solve this problem, however if there is a workaround or a fix in Terraform that would solve this, then that would be good enough for me.
Not sure about others reasons behind this?

@nlamirault
Copy link
Contributor

👍

4 similar comments
@bborysenko
Copy link

👍

@wakwanza
Copy link

+1

@kchygoe
Copy link

kchygoe commented Sep 2, 2015

+1

@vikingops
Copy link

👍

@jsmartin
Copy link

jsmartin commented Sep 3, 2015

Fix local_exec's buffering of stdout and just call the ansible-playbook command. Couple that with a terraform dynamic inventory script. That's going to be the most flexible.

@IanVS
Copy link

IanVS commented Sep 3, 2015

Ansible has its own dynamic inventory scripts as well. The advantage to using them rather than Terraform dynamic inventory is that you can continue to run the Ansible playbooks (for updates, upgrades, deployments, etc.) after you have used Terraform to spin up the resources.

@jsmartin
Copy link

jsmartin commented Sep 3, 2015

@IanVS by "terraform dynamic inventory script" I'm referring to an Ansible dynamic inventory script that pulls form Terraform :).

@lukehoersten
Copy link
Author

It's not so much about kicking off Ansible as it is about communicating the information Terraform has to Ansible. Ansible dynamic inventory is many times not enough (for example groups are auto-generated from tags etc). Ansible plays however typically use nice group names like "webservers". What would be ideal is something similar to what Vagrant does with Ansible:
http://docs.vagrantup.com/v2/provisioning/ansible.html

So, after running Terraform, Terraform now knows the custom VPC DNS domain names I've given each host. This is not easily known to Ansible. Also, Terraform could generate a static inventory w/ groups of my choosing etc.

This is just what I had in mind and a lot of it comes form Vagrant. Perhaps others are thinking of other features.

@ghost
Copy link

ghost commented Sep 7, 2015

It would be great if stdout / wasn't buffered, at least as a stop-gap.

@riccardofreixo
Copy link

+1

12 similar comments
@dflower-rms
Copy link

+1

@d33d33
Copy link

d33d33 commented Sep 16, 2015

+1

@pmastalerz
Copy link

👍

@beeradb
Copy link

beeradb commented Sep 18, 2015

+1

@michaelandersen
Copy link

+1

@danieslo
Copy link

+1

@kelseyfrancis
Copy link

+1

@cad
Copy link

cad commented Oct 2, 2015

+1

@sidick
Copy link

sidick commented Oct 3, 2015

+1

@jdoss
Copy link

jdoss commented Oct 10, 2015

+1

@dereulenspiegel
Copy link

+1

@asafdav
Copy link

asafdav commented Oct 15, 2015

+1

@andor-pierdelacabeza
Copy link

@cochransj @alessandro-dibella-rockalltech @visokoo @mr-future @schmitzcc And all the "+1" or ":+1:" posters, previous and to come: Stop Spamming.

If you wanna show support, instead of posting a comment and notifying the 100 people subscribed to it, there's an awesome "Add your reaction" button for each commit and issue, were you can give 'thumbs up' or 'thumbs down' or wathever you feel like giving to this issue. 🤦‍♂️

@rehmanzile
Copy link

👍

@stack72
Copy link
Contributor

stack72 commented Apr 18, 2017

Hi Friends,

Just an FYI, I opened an issue on a terraform-provisioner-ansible to talk about this. The maintainer of that project is going to be doing some work on it and then he will be looking at, potentially, opening a PR to the core repo

While we'd love to see something like this, we don't currently have any plans to implement this ourselves. Until then, this issue is unlikely to see any movement and remain stale. We're trying to prune the stale issues (that aren't going to be addressed anytime soon) by closing them. Note that we only do this for enhancement requests and not bugs.

Thanks

@stack72

@stack72 stack72 closed this as completed Apr 18, 2017
@FlorinAndrei
Copy link

@stack72 That issue you're referencing - you've actually closed it. Why reference it here, then?

@stack72
Copy link
Contributor

stack72 commented Apr 19, 2017

@FlorinAndrei I am now waiting on the writer of the provisioner

This is classed as something we are not going to be working on ourselves - I am in email talks with the writer

@rcaught
Copy link

rcaught commented Jun 5, 2017

@stack72 there hasn't been movement on that repo for over a year. Any updates? I would really like to run an Ansible provisioner, but don't feel comfortable when things go this stale.

@rcaught
Copy link

rcaught commented Jun 5, 2017

Also, I've read the other issue, but this seems like it needs someone just to move the current version (with PR's merged that fix some things) into core. Otherwise we could be sitting here waiting for a rewrite forever.

@stack72
Copy link
Contributor

stack72 commented Jun 5, 2017

Hi @rcaught

I totally understand your concerns - as you can see, I did ask the question over there and the owner said he was going to do it. Unfortunately, I don't really feel as though it's my place to pick someone's code and move it to Terraform core - we haven't written it and don't own it

I am hopeful this will get resolved though

Thanks

Paul

@nealabh
Copy link

nealabh commented Jun 22, 2017

Hi all

was looking for some similar kind of a solution for provisioning azure VMs
something like this worked well for me.

provisioner "local-exec" {
command = <<EOD
cat <> azure_hosts
${element(azurerm_public_ip.mh..ip_address, count.index)}
EOF
EOD
}
}
resource "null_resource" "ansible" {
triggers {
host_ip = "${element(azurerm_public_ip.mh.
.ip_address, count.index)}"
}
provisioner "local-exec" {
command = "sleep 1m && ansible-playbook -i azure_hosts deploy.yml"
}
}

creating a null resource helped me generate an un-buffered output.

what do you guys think on this?

@wjam
Copy link
Contributor

wjam commented Aug 15, 2017

It seems like the provisioner that's been linked here is only designed to run Ansible on the machine that has been created rather than running from the machine that is running Terraform. Wouldn't a better approach be similar to how Packer already does this?

Packer accomplishes this by for the ansible provisioner (Ansible runs on the machine running packer) by proxying the commands through an in-memory SSH server to the remote instance, thus reusing already configured connection.

For ansible-local (Ansible runs on the machine that has just been created), it's just a case of copying up a bunch of files and then running the Ansible command.

wjam added a commit to wjam/terraform that referenced this issue Aug 16, 2017
This adds the capability of provisioning a resource using Ansible that is running locally to the resource being provisioned.

This fixes part of hashicorp#2661.
wjam added a commit to wjam/terraform that referenced this issue Aug 16, 2017
This adds the capability of provisioning a resource using Ansible that is running locally to the resource being provisioned.

This fixes part of hashicorp#2661.
wjam added a commit to wjam/terraform that referenced this issue Aug 16, 2017
This adds the capability of provisioning a resource using Ansible that is running locally to the resource being provisioned.

This fixes part of hashicorp#2661.
@radekg
Copy link

radekg commented Feb 2, 2018

I've created this recently, this runs ansible on the provisioned host: https://github.com/radekg/terraform-provisioner-ansible.
The local one will be ready over the weekend or so. I'd be happy to contribute into the core, if anyone would be interested.

Edit: But I do understand the feature creep story, in such case, just a heads up. The plugin linked above works fine with terraform 0.11.x.

@radekg
Copy link

radekg commented Feb 5, 2018

I've added the local mode to the https://github.com/radekg/terraform-provisioner-ansible. Currently with a few caveats but the first version is there: https://github.com/radekg/terraform-provisioner-ansible#running-in-local-mode.

@monokal
Copy link

monokal commented May 13, 2018

Why did this ticket get closed? I find it odd that we have a Chef Provisioner but no supported Ansible Provisioner with so much interest being shown. local-exec isn't a nice or reliable method of executing Ansible.

@jullianoacqio
Copy link

+1

@devops-rob
Copy link

I agree with @monokal completely. Ansible and terraform are a marriage made in heaven! To not have native provisioner support for it or a willingness to introduce such a provisioner is beyond me. I use terrafrom because it makes deployment and management tasks easy, until we get to the ansible bit so reading some of the comments, I can understand why some people have opted to use ansible modules instead but then again, it's not ideal either. There seems to be a huge demand for such a provisoner looking at this thread so for me it's a no-brainer but somehow this has been closed :-/

@radekg
Copy link

radekg commented Jun 2, 2018

Looking at the comments above, I'd love to repeat, happy to see https://github.com/radekg/terraform-provisioner-ansible contributed to the core. There are definitely a bunch of features to be implemented (the biggest one being Windows support) but it is more or less complete. It supports local and remote deployments, quite well tested on non-Windows deployments at this moment in time.

@monokal
Copy link

monokal commented Jun 2, 2018 via email

@bkmeneguello
Copy link

What are the criterions to add a feature to core? Maintenance? I think @radekg ansible provisioner is amazing and if promoted to core it would be amazing.

@radekg
Copy link

radekg commented Sep 22, 2018

The https://github.com/radekg/terraform-provisioner-ansible is now available via Terraform Module Registry. Not sure if this is the correct distribution path but I was not able to think of anything better.

I'm not sure if the file naming in prebuilt releases will cause a problem when Terraform resolves the provisioner (I would assume it might be a problem). Please let me know if that is a problem, indeed.

Edit: it turned out that the released files naming was an issue. I have documented this in the readme and supplied a shell script to fetch and deploy a version of the provisioner: https://github.com/radekg/terraform-provisioner-ansible#installation.

@nwipfli
Copy link

nwipfli commented Sep 25, 2018

Just tested the v.1.0.0 and it is working great. Very useful provisioner.

@radekg
Copy link

radekg commented Oct 7, 2018

I have released version 2.0.0 of the Ansible provisioner:

2.0.0 is not a drop-in replacement. Changes are documented: https://github.com/radekg/terraform-provisioner-ansible#breaking-changes. I have also provided some examples: https://github.com/radekg/terraform-provisioner-ansible/tree/master/examples.

Additionally, I have created a pull request for terraform. #19021 reflects the the commit radekg/terraform-provisioner-ansible@47d9435 (radekg@fac2403). The intent is to contribute the provisioner to Terraform.

@dmitrypol
Copy link

+1. Would be great to have official support.

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashicorp hashicorp locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests