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

Ansible HostGroup Support #16

Closed
proffalken opened this issue Jul 22, 2015 · 12 comments · Fixed by #22
Closed

Ansible HostGroup Support #16

proffalken opened this issue Jul 22, 2015 · 12 comments · Fixed by #22

Comments

@proffalken
Copy link

At present there doesn't appear to be a way to output the data from terraform as Ansible Host Groups to allow for multiple hosts to be configured via a single play.

For example, a play that starts with "hosts: webservers" doesn't know that "aws_instance.webserver.0" should belong to the "webservers" ansible group.

It would be nice to have some way of mapping aws_instance.webserver.* to a group or similar.

@adammck
Copy link
Owner

adammck commented Jul 22, 2015

Yes, this would be very useful, especially when multiple identical resources are created with Terraform's count parameter. They should all be returned as a single host group.

@kvz
Copy link
Contributor

kvz commented Oct 6, 2015

+1

3 similar comments
@girvo
Copy link

girvo commented Nov 3, 2015

+1

@afritzler
Copy link

+1

@zihaoyu
Copy link

zihaoyu commented Nov 13, 2015

+1

@jackspirou
Copy link

Working on a little patch with @jbehling that should help with this. You can find it here master...jackspirou:master

The idea is that metadata.groups would be string of comma separated groups that would be parsed upon the --list flag. So values like "metadata.groups": "mongosc,mongos,mongoc", might produce something like the following output:

{
  "mongoc":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "mongos":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "mongosc":["10.10.10.101","10.10.10.102","10.10.10.103"],
  "server.0":["10.10.10.101"],
  "server.1":["10.10.10.102"],
  "server.2":["10.10.10.103"]
}

@jackspirou
Copy link

@adammck Let me and @jbehling know what you think of PR #21 and if it helps solve this issue.

@vasiliyb
Copy link

vasiliyb commented Dec 9, 2015

+1

@adammck
Copy link
Owner

adammck commented Dec 10, 2015

Please check out #22 for an implementation of this. Feedback would be very much appreciated.

@johnwards
Copy link

@adammck So glad I found this today :) I'm just doing some elasticsearch stuff with terraform and ansible so needed groups.

Works perfectly, however just an FYI from terraform that you'll need to come up with a different strategy for naming things.

Warnings:
  * aws_instance.eip-elasticsearch.2: eip-elasticsearch.2: resource name can only contain letters, numbers, dashes, and underscores.
This will be an error in Terraform 0.4
  * aws_instance.eip-elasticsearch.1: eip-elasticsearch.1: resource name can only contain letters, numbers, dashes, and underscores.
This will be an error in Terraform 0.4

@adammck
Copy link
Owner

adammck commented Jan 5, 2016

Thanks for the heads up, @johnwards! I don't entirely understand the warning, since those resource names -- something.index -- were presumably generated by Terraform itself, via the count param. Or perhaps it's specific to your templates?

@johnwards
Copy link

Ah, so this might be my problem I guess. I directly named my ec2 instances:

resource "aws_instance" "eip-elasticsearch.1"

resource "aws_instance" "eip-elasticsearch.2"

So in this case this is my bad for not realising there is a count param and putting it in manually, but I do think that having instances of different settings (security groups, instance size etc) but in the same group is probably a valid use case and you could achieve it this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants