Open fred-gb opened 4 years ago
chmod +x
would have been my first guess, but I see you've tried that.
For some reason, Ansible is trying to parse the script as an inventory file. That would seem to suggest that it wasn't able to execute it, despite the permissions setting you already tried.
Try executing the script yourself, ie ./terraform.py
from Bash or other shell. It should spit out some Ansible inventory JSON. Or, if there's an error that might help you figure out what's wrong.
Hello, I found something about my mistake.
When:
ansible -i inventories/betatest/terraform.py -m ping all
I have the parse error.
When:
cd inventories/betatest/terraform.py
and
ansible -i inventories/betatest/terraform.py -m ping all
Tadaaaa:
mariadb-master | SUCCESS => {
"changed": false,
"ping": "pong"
}
redis01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
wordpress01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
haproxy01 | SUCCESS => {
"changed": false,
"ping": "pong"
}
It's works!
I need to be in the same directory.
So if I want to play a playbook, like:
ansible-playbook -i inventories/betatest/terraform.py play/test.yml
I have the parse error.
How I can do to use terraform.py with differents directories? Because I need to change inventory.
inventories/
`-- betatest
|-- group_vars
| `-- all.yml
|-- host_vars
| `-- host01.yml
|-- terraform.py
`-- terraform.tfstate
-- betatest1
|-- group_vars
| `-- all.yml
|-- host_vars
| `-- host01.yml
|-- terraform.py
`-- terraform.tfstate
-- betatest2
|-- group_vars
| `-- all.yml
|-- host_vars
| `-- host01.yml
|-- terraform.py
`-- terraform.tfstate
Thanks
Perhaps it's trying to run it, and falls back to reading the file when it fails. I can't recall if that's how it behaved when I was developing it.
I think what you want is to set the Terraform project path. There's an override for that as an environment variable. See the README for details. https://github.com/nbering/terraform-inventory#ansible_tf_dir
Thansk, that is!
But how to fix configuration of terraform.py to not have to add each time ANSIBLE_TF_DIR=blablablablabla ansible -i terraform.py -m ping all
Thanks
Finally, I change string in terraform.py
TERRAFORM_DIR = os.environ.get('ANSIBLE_TF_DIR', '/full/path/to/workdir/')
And it's works!
Hello, Terraform 0.12.17 Ansible 2.9.6
Already do chmod +x
Part of my tfstate:
Where is my error?