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

workspaces not supported #23

Open
Rafaelrico7 opened this issue Nov 20, 2020 · 4 comments
Open

workspaces not supported #23

Rafaelrico7 opened this issue Nov 20, 2020 · 4 comments

Comments

@Rafaelrico7
Copy link

Hi

I'm using the Gitlab Remote State Backend for my terraform state.
While executing the terraform.py I get the following error:

$ ansible-playbook -i /etc/ansible/terraform.py ../ansible/playbook.yml [WARNING]: * Failed to parse /etc/ansible/terraform.py with script plugin: Inventory script (/etc/ansible/terraform.py) had an execution error: workspaces not supported [WARNING]: * Failed to parse /etc/ansible/terraform.py with ini plugin: /etc/ansible/terraform.py:2: Error parsing host definition ''''': No closing quotation [WARNING]: Unable to parse /etc/ansible/terraform.py as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

chmod +x was executed on the file and I also tried:
ANSIBLE_TF_DIR=/path/to/terraform/workdir/ ansible -i terraform.py ...

what is my error?

@nbering
Copy link
Owner

nbering commented Nov 23, 2020

Try running terraform.py by itself, without Ansible to see if you get the inventory output you expect as JSON. That might provide some meaningful next steps to look at.

I checked the Ansible changelog to see if there's breaking changes lately, but the docs claim continued compatibility with inventory scripts. Still... it might help to know what version of Ansible and Terraform you're using.

@nbering
Copy link
Owner

nbering commented Nov 24, 2020

By the way... actual error you're getting says Ansible is trying to read your script file as a static ini-formatted inventory file. This might mean the permissions were not correct to execute the file, or perhaps it failed to execute and Ansible is falling back to parsing it as a static inventory.

@mantiz
Copy link

mantiz commented Jan 11, 2021

@Rafaelrico7 I had the same problem. It seems like gitlab does not (yet) support workspaces, so I removed these lines https://github.com/nbering/terraform-inventory/blob/master/terraform.py#L374-L381 and removed one level of indentation for these lines https://github.com/nbering/terraform-inventory/blob/master/terraform.py#L382-L390.

In addition, I had to remove the encoding parameter in this line https://github.com/nbering/terraform-inventory/blob/master/terraform.py#L390 because it was removed with python 3.9 (https://docs.python.org/3/library/json.html#json.loads).

With those modifications I was able to use this script, hope it helps.

@nbering Thanks for the script 💐

@acook8
Copy link

acook8 commented Feb 18, 2021

@nbering I had the same error as well. I'm running Terraform version 0.14.6 and Python 3.8.5. To fix it I changed
tf_workspace = [TERRAFORM_PATH, 'workspace', 'select', TERRAFORM_WS_NAME]
to
tf_workspace = [TERRAFORM_PATH, 'select', TERRAFORM_WS_NAME]
here:

tf_workspace = [TERRAFORM_PATH, 'workspace', 'select', TERRAFORM_WS_NAME]

I wonder if there was an update to Terraform that caused the issue

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

4 participants