Closed hwts closed 3 months ago
Providers don't generally send output to Terraform during provisioning.
You can capture the playbook output and expose it via the ansible_playbook_stdout
output from the resource:
https://registry.terraform.io/providers/ansible/ansible/latest/docs/resources/playbook#ansible_playbook_stdout
Please try codes like below Change variables with your resource name
output "playbook_stderr" {
value = ansible_playbook.<RESOURCE_NAME>.ansible_playbook_stderr
}
output "playbook_stdout" {
value = ansible_playbook.<RESOURCE_NAME>.ansible_playbook_stdout
}
@hwts
This is the design that allows you to see the process of making a playbook
provisioner "local-exec" {
working_dir = "./ansible/"
command = "ansible-playbook -u ${var.ssh_user} --key-file ${var.ssh_keys["priv"]} -i inventory site.yml"
}
It can work, if resources was created. In my case resource creation failed because of some error and there is absolutely no way to see error, only to run ansible-playbook
manually. TF_LOG=TRACE
do not show provider output too
I have an issue with that as well. Lets say the playbook gets stuck on something and won't time-out. I have no idea of what caused it. This makes playbooks really hard to debug.
The provisioner approach is okay but it's sub-optimal.
If you set ignore_playbook_failure
to true, then terraform will continue to execute as if the resource was successful. This will then populate ansible_playbook_stderr
and ansible_playbook_stdout
.
Then in my outputs:
output "ansible_playbook_stderr" {
value = ansible_playbook.nginx[*].ansible_playbook_stderr
}
output "ansible_playbook_stdout" {
value = ansible_playbook.nginx[*].ansible_playbook_stdout
}
I agree it's a bit annoying as maybe this could be output with TRACE logging level. If you have more resources to execute after the playbook is supposed to run, then setting ingore_playbook_failure
to true is going to break the rest of the terraform run.
I would recommend commenting on #39 with complaints/suggestions for how to deal with playbook errors.
We have improved logging with v1.2.0 of this provider. As stated above, using ignore_playbook_failure
can be helpful for debugging playbook problems.
The output of ansible is not displayed.
instead