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

Bug: Running terraform inventory on empty tfstate returns invalid inventory #48

Closed
marcospedreiro opened this issue Oct 31, 2016 · 0 comments

Comments

@marcospedreiro
Copy link

Context

I define a cluster-name for some infrastructure I'm provisioning in aws. Before I run terraform apply I want to run terraform destroy on that cluster-name to make sure that any previous/existing infrastructure is cleaned up before I create new infrastructure.

Bug

If I pull tfstate for cluster-name that does not exist and then try to run an ansible playbook I get the following error:

ERROR! The file /usr/local/bin/terraform-inventory is marked as executable, but failed to execute correctly. If this is not supposed to be an executable script, correct this with `chmod -x /usr/local/bin/terraform-inventory`.
You defined a group "all" with bad data for the host list:
 {u'hosts': None, u'vars': {<vars here>}}
'utf8' codec can't decode byte 0x80 in position 24: invalid start byte
'utf8' codec can't decode byte 0x80 in position 24: invalid start byte

If I run

/usr/local/bin/terraform-inventory --list <empty-tfstate> | jq .

I get

{
  "all": {
    "hosts": null,
    "vars": {
      <vars here>
    }
  }
}

If I write this to a file and point ansible to it directly I get:

ERROR! 'NoneType' object is not iterable
./test-inventory:2: Expected key=value host variable assignment, got: {

If I change the null field to an empty json array as below:

{
  "all": {
    "hosts": [], 
    "vars": {
      <vars here>
    }
  }
}

And then run ansible with this file it runs as expected.

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

No branches or pull requests

1 participant