Closed dnitsch closed 6 years ago
This inventory script is meant to be run after Terraform is done. It uses terraform state pull
to get your Terraform State, so if you run while changes are being applied, the state will be locked.
That said, it looks like you don't have executable permissions on terraform.py.
Try chmod +x terraform.py
.
I could be wrong above. Can you share your ansible version and ansible.cfg?
Ok, that could have been part of the problem (the locking, d'oh, I mean, not the perms that was fine) - in fact it was most likely that when ran as part of the null_resource on trigger. I have moved it out to separate callback application so that it's guaranteed to run after the state has been released.
If that isn't the problem, I'd next look at whether you've somehow configured Ansible 2.4+ to restrict the Inventory parsing mechanism. There's a bunch of things to look at there if this still doesn't work after you run outside the Terraform session.
Sounds like no changes were required to fix this issue. Closing... will reopen if there's still a problem.
There seems to be a problem parsing the terraform.py inside a local-exec provisioner in Terraform
Taking this as an example trigger in terraform to run ansible
gives me this output
when the same command is run in the terminal it works just fine
$ cd /Users/moi/ansible/sandbox-test; ANSIBLE_TF_DIR=/Users/moi/foo/git-dev/idam/idam-iac/devops-idam-static-dev ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook --inventory-file=/Users/moi/ansible/sandbox-test/terraform.py jenkins/master.yml
Should it be used like that within Terraform?
As I am very close to creating a separate application to that is triggered on remote state callback that will then trigger the ansible scripts, and have a feeling it could be a more logical way to separate the concern and domains.
Wondering if anyone else came across the same issue.