-
Notifications
You must be signed in to change notification settings - Fork 322
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 all group as per Ansible inventory script conventions #46
Conversation
9c081a0
to
ee7178e
Compare
Not sure why the tests are failing. I'm a go beginner. |
1c036fe
to
ab55899
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change that cause hosts to be missed.
} | ||
sort.Strings(strs) | ||
i := sort.SearchStrings(strs, item) | ||
if i < len(strs) && strs[i] != item { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the goDocs: https://golang.org/pkg/sort/#SearchStrings, this conditional excludes IP ranges that would go at the end of the list. Consider something like:
if i == len(strs) || (i < len(strs) && strs[i] != item) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here c735e9f
@@ -139,7 +139,15 @@ const exampleStateFile = ` | |||
|
|||
const expectedListOutput = ` | |||
{ | |||
"all": {"datacenter": "mydc", "olddatacenter": "<0.7_format", "ids": [1, 2, 3, 4], "map": {"key": "value"}}, | |||
"all": { | |||
"hosts": ["10.0.0.1"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to update the test cases to test the unique host filtering functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done here 082d2ec
Thank you very much for the patch, and especially for the comprehensive explanation of the issue. Looks good to me. Merging. |
FYI, this PR is included in the v0.7-pre release. I'd greatly appreciate it if you could give it a try. |
Tested, looks good! |
I first noticed that I was unable to run
terraform-inventory --list
without first exportingTF_STATE=.terraform/terraform.tfstate
and as per the README it appears as though having to export TF_STATE was optional. Second, I noticed that when runningansible-playbook
with the--list-hosts
flagansible-playbook
would say there were no hosts found. When I removed--list-hosts
it detected the host that the playbook should run against.I then ran
git bisect
to track down the problem. And I was led to this commit 6ead28e. I noticed that in cli.go this change added an "all" group to the Ansible inventory, so I went to check the Ansible docs regarding the format expected from a script.http://docs.ansible.com/ansible/developing_inventory.html#script-conventions
The JSON generated from the master branch creates an "all" group containing a mapping of variable keys and values. According to the Ansible docs that mapping should be under the "vars" key of the "all" group.
After making these changes it has fixed both of the problems I was encountering.