ansible / terraform-provider-ansible

community terraform provider for ansible
https://registry.terraform.io/providers/ansible/ansible/latest
GNU General Public License v3.0
183 stars 42 forks source link

Error during Terraform apply with Ansible playbook #105

Closed spham closed 2 months ago

spham commented 3 months ago

During a Terraform apply operation, an error occurs with the ansible_playbook resource. The error message is

Empty Summary: This is always a bug in the provider and should be reported to the provider developers. 

This happens when applying the following Terraform configuration and only on gitlab-ci:

resource "ansible_playbook" "web_deployment" {
  playbook   = "../ansible/playbook.yml"
  name       = hcloud_server.web.ipv4_address
  replayable = true
  extra_vars = {
    ansible_user = "root"
  }
}

terraform {
  required_providers {
    hcloud = {
      source  = "hetznercloud/hcloud"
      version = "1.45.0"
    }
    ansible = {
      source  = "ansible/ansible"
      version = "1.2.0"
    }
  }
}

provider "hcloud" {
  token = var.hcloud_token
}

provider "ansible" {}
dimi4ik commented 2 months ago

@spham

Community Note

Please vote on this issue by adding a đź‘Ť reaction to the original issue to help the community and maintainers prioritize this request Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request

Description

I have the same error when I run Terraform via GitLab CI-CD Pipeline. if I run the same locally without CI-CD pipeline then it works. If I can give you the logs etc, please let me know.

Terraform has been successfully initialized! Acquiring state lock. This may take a few moments... ansible_playbook.createADS: Creating... ╷ │ Error: Empty Summary: This is always a bug in the provider and should be reported to the provider developers. │  │  with ansible_playbook.createADS, │  on _04_Create_DCs_vm.tf line 178, in resource "ansible_playbook" "createADS": │  178: resource "ansible_playbook" "createADS" { │  │ ansible-playbook ╵

dimi4ik commented 2 months ago

Below you will find the debug log


2024-04-13T12:18:15.900Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received request: tf_proto_version=5.4 tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 tf_resource_type=ansible_playbook tf_provider_addr=provider tf_rpc=ValidateResourceTypeConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:706 @module=sdk.proto timestamp=2024-04-13T12:18:15.900Z
2024-04-13T12:18:15.900Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Sending request downstream: @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:20 tf_provider_addr=provider tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 tf_rpc=ValidateResourceTypeConfig @module=sdk.proto tf_proto_version=5.4 tf_resource_type=ansible_playbook timestamp=2024-04-13T12:18:15.900Z
2024-04-13T12:18:15.901Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Calling downstream: tf_resource_type=ansible_playbook @module=sdk.helper_schema tf_provider_addr=provider tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 tf_rpc=ValidateResourceTypeConfig @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/grpc_provider.go:286 timestamp=2024-04-13T12:18:15.901Z
2024-04-13T12:18:15.903Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Called downstream: @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/grpc_provider.go:288 tf_rpc=ValidateResourceTypeConfig @module=sdk.helper_schema tf_provider_addr=provider tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 tf_resource_type=ansible_playbook timestamp=2024-04-13T12:18:15.901Z
2024-04-13T12:18:15.903Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received downstream response: diagnostic_error_count=0 tf_req_duration_ms=3 tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 @module=sdk.proto diagnostic_warning_count=0 tf_proto_version=5.4 tf_provider_addr=provider tf_resource_type=ansible_playbook @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 tf_rpc=ValidateResourceTypeConfig timestamp=2024-04-13T12:18:15.903Z
2024-04-13T12:18:15.903Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Served request: tf_resource_type=ansible_playbook tf_rpc=ValidateResourceTypeConfig @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:726 tf_provider_addr=provider tf_req_id=a22c83ee-854c-51da-83a8-04aaba016922 @module=sdk.proto tf_proto_version=5.4 timestamp=2024-04-13T12:18:15.903Z
2024-04-13T12:18:15.903Z [TRACE] GRPCProvider: PlanResourceChange
2024-04-13T12:18:15.904Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received request: @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:797 tf_proto_version=5.4 tf_resource_type=ansible_playbook tf_rpc=PlanResourceChange @module=sdk.proto tf_provider_addr=provider tf_req_id=07b2636a-3d80-781f-0b76-0646d780aab3 timestamp=2024-04-13T12:18:15.904Z
2024-04-13T12:18:15.904Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Sending request downstream: @module=sdk.proto tf_req_id=07b2636a-3d80-781f-0b76-0646d780aab3 tf_proto_version=5.4 tf_provider_addr=provider tf_resource_type=ansible_playbook tf_rpc=PlanResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:20 timestamp=2024-04-13T12:18:15.904Z
2024-04-13T12:18:15.905Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received downstream response: @module=sdk.proto tf_proto_version=5.4 tf_provider_addr=provider tf_req_id=07b2636a-3d80-781f-0b76-0646d780aab3 @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 diagnostic_error_count=0 diagnostic_warning_count=0 tf_req_duration_ms=0 tf_resource_type=ansible_playbook tf_rpc=PlanResourceChange timestamp=2024-04-13T12:18:15.905Z
2024-04-13T12:18:15.905Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Served request: @module=sdk.proto tf_proto_version=5.4 tf_provider_addr=provider tf_rpc=PlanResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:823 tf_req_id=07b2636a-3d80-781f-0b76-0646d780aab3 tf_resource_type=ansible_playbook timestamp=2024-04-13T12:18:15.905Z
2024-04-13T12:18:15.905Z [WARN]  Provider "registry.terraform.io/ansible/ansible" produced an invalid plan for ansible_playbook.createADS, but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .force_handlers: planned value cty.False for a non-computed attribute
      - .ansible_playbook_binary: planned value cty.StringVal("ansible-playbook") for a non-computed attribute
      - .diff_mode: planned value cty.False for a non-computed attribute
      - .ignore_playbook_failure: planned value cty.False for a non-computed attribute
      - .verbosity: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .labeck_mode: planned value cty.False for a non-computed attribute
2024-04-13T12:18:15.905Z [TRACE] checkPlannedChange: Verifying that actual change (action Create) matches planned change (action Create)
ansible_playbook.createADS: Creating...
2024-04-13T12:18:15.906Z [INFO]  Starting apply for ansible_playbook.createADS
2024-04-13T12:18:15.907Z [DEBUG] ansible_playbook.createADS: applying the planned Create change
2024-04-13T12:18:15.907Z [TRACE] GRPCProvider: ApplyResourceChange
2024-04-13T12:18:15.908Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received request: tf_req_id=202406db-24a1-c419-147c-a24c86025332 tf_resource_type=ansible_playbook tf_rpc=ApplyResourceChange @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:832 @module=sdk.proto tf_proto_version=5.4 tf_provider_addr=provider timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.908Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Sending request downstream: @module=sdk.proto tf_provider_addr=provider tf_req_id=202406db-24a1-c419-147c-a24c86025332 tf_resource_type=ansible_playbook @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:20 tf_proto_version=5.4 tf_rpc=ApplyResourceChange timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.908Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 [DEBUG] setting computed for "args" from ComputedKeys: timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.908Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Calling downstream: @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/resource.go:908 @module=sdk.helper_schema tf_provider_addr=provider tf_rpc=ApplyResourceChange tf_req_id=202406db-24a1-c419-147c-a24c86025332 tf_resource_type=ansible_playbook timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.908Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 [ANSIBLE ARGS]:: timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 [-e hostname=51.103.231.172 -e ansible_password=u0ql!o#&8Xhk!I_rGg08iPT* -e domain_netbios_name=m000 -e ansible_port=5986 -e ansible_winrm_transport=credssp -e ansible_winrm_server_cert_validation=ignore -e ansible_winrm_scheme=https -e apcMandant=000 -e user_password=u0ql!o#&8Xhk!I_rGg08iPT* -e domain_name=m000.abxcloud.lab -e ansible_user=adminuser -e apcKunde=SIT Engineering AG -e ansible_connection=winrm playbookRollen.yml]: timestamp=2024-04-13T12:18:15.908Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 LOG [ansible-playbook]: playbook = playbookRollen.yml: timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 Inventory /tmp/.inventory-3262951936.ini was created: timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 Temp Inventory File: /tmp/.inventory-3262951936.ini: timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 LOG [ansible-playbook]:: timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.909Z [INFO]  provider.terraform-provider-ansible_v1.2.0: 2024/04/13 12:18:15 LOG [ansible-playbook]: didn't wait for playbook to execute: exec: not started: timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.910Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Called downstream: tf_provider_addr=provider tf_resource_type=ansible_playbook @caller=github.com/hashicorp/terraform-plugin-sdk/v2@v2.32.0/helper/schema/resource.go:910 @module=sdk.helper_schema tf_req_id=202406db-24a1-c419-147c-a24c86025332 tf_rpc=ApplyResourceChange timestamp=2024-04-13T12:18:15.909Z
2024-04-13T12:18:15.910Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Received downstream response: tf_rpc=ApplyResourceChange diagnostic_error_count=1 diagnostic_warning_count=0 tf_proto_version=5.4 tf_resource_type=ansible_playbook @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/tf5serverlogging/downstream_request.go:40 @module=sdk.proto tf_provider_addr=provider tf_req_duration_ms=2 tf_req_id=202406db-24a1-c419-147c-a24c86025332 timestamp=2024-04-13T12:18:15.910Z
2024-04-13T12:18:15.910Z [ERROR] provider.terraform-provider-ansible_v1.2.0: Response contains error diagnostic: tf_proto_version=5.4 tf_resource_type=ansible_playbook tf_rpc=ApplyResourceChange @module=sdk.proto diagnostic_severity=ERROR diagnostic_summary="Empty Summary: This is always a bug in the provider and should be reported to the provider developers." @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/internal/diag/diagnostics.go:62 diagnostic_detail=ansible-playbook tf_provider_addr=provider tf_req_id=202406db-24a1-c419-147c-a24c86025332 timestamp=2024-04-13T12:18:15.910Z
2024-04-13T12:18:15.910Z [TRACE] provider.terraform-provider-ansible_v1.2.0: Served request: tf_proto_version=5.4 tf_req_id=202406db-24a1-c419-147c-a24c86025332 @caller=github.com/hashicorp/terraform-plugin-go@v0.21.0/tfprotov5/tf5server/server.go:858 @module=sdk.proto tf_provider_addr=provider tf_resource_type=ansible_playbook tf_rpc=ApplyResourceChange timestamp=2024-04-13T12:18:15.910Z
2024-04-13T12:18:15.910Z [TRACE] maybeTainted: ansible_playbook.createADS encountered an error during creation, so it is now marked as tainted
2024-04-13T12:18:15.911Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for ansible_playbook.createADS
2024-04-13T12:18:15.911Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for ansible_playbook.createADS
2024-04-13T12:18:15.911Z [TRACE] evalApplyProvisioners: ansible_playbook.createADS is tainted, so skipping provisioning
2024-04-13T12:18:15.911Z [TRACE] maybeTainted: ansible_playbook.createADS was already tainted, so nothing to do
2024-04-13T12:18:15.911Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState to workingState for ansible_playbook.createADS
2024-04-13T12:18:15.911Z [TRACE] NodeAbstractResouceInstance.writeResourceInstanceState: writing state object for ansible_playbook.createADS
2024-04-13T12:18:15.911Z [DEBUG] State storage *remote.State declined to persist a state snapshot
2024-04-13T12:18:15.911Z [ERROR] vertex "ansible_playbook.createADS" error: Empty Summary: This is always a bug in the provider and should be reported to the provider developers.
2024-04-13T12:18:15.911Z [TRACE] vertex "ansible_playbook.createADS": visit complete, with errors
2024-04-13T12:18:15.912Z [TRACE] dag/walk: upstream of "output.playbook_stdout (expand)" errored, so skipping
2024-04-13T12:18:15.912Z [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/ansible/ansible\"] (close)" errored, so skipping
2024-04-13T12:18:15.912Z [TRACE] dag/walk: upstream of "output.playbook_stderr (expand)" errored, so skipping
2024-04-13T12:18:15.912Z [TRACE] dag/walk: upstream of "root" errored, so skipping
2024-04-13T12:18:15.912Z [DEBUG] states/remote: state read serial is: 48; serial is: 48
2024-04-13T12:18:15.912Z [DEBUG] states/remote: state read lineage is: 1348a66b-7b6c-e2b8-3b93-97b2003357c4; lineage is: 1348a66b-7b6c-e2b8-3b93-97b2003357c4
2024-04-13T12:18:15.914Z [DEBUG] POST https://gitlab.demo-lab.lab/api/v4/projects/5121/terraform/state/default?ID=43eadc01-6e90-082d-a402-d53203d6cf17
â•·
│ Error: Empty Summary: This is always a bug in the provider and should be reported to the provider developers.
│ 
│   with ansible_playbook.createADS,
│   on _04_Create_DCs_vm.tf line 178, in resource "ansible_playbook" "createADS":
│  178: resource "ansible_playbook" "createADS" {
│ 
│ ansible-playbook
╵
2024-04-13T12:18:16.619Z [DEBUG] DELETE https://gitlab.demo-lab.lab/api/v4/projects/5121/terraform/state/default/lock
2024-04-13T12:18:16.892Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-04-13T12:18:16.894Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/ansible/ansible/1.2.0/linux_amd64/terraform-provider-ansible_v1.2.0 pid=127
2024-04-13T12:18:16.894Z [DEBUG] provider: plugin exited

section_end:1713010697:step_script
section_start:1713010697:cleanup_file_variables
Cleaning up project directory and file based variables

section_end:1713010697:cleanup_file_variables
ERROR: Job failed: command terminated with exit code 1
``` `
gravesm commented 2 months ago

I can't be certain since I can't reproduce this, but I think there may be a race condition with https://github.com/ansible/terraform-provider-ansible/blob/34b158a5ee310ee08432b098aa4ab01aa729fc07/provider/resource_playbook.go#L687 It shouldn't Wait() because CombinedOutput() has already done that.

dimi4ik commented 2 months ago

Hello , @gravesm Thanks for the feedback. đź‘Ť I use an internal sharerd runner in the pipeline and checked that Ansible is not installed.

@spham Can you please check if you have Ansible installed?

@gravesm Can you please integrate in the ansible-teraform provider and check whether Ansible is installed, if not show a clear error message Thanks

spham commented 2 months ago

hi, it's ok after setup ansible. thanks you

dimi4ik commented 2 months ago

hi, it's ok after setup ansible. thanks you @spham Can you please tell me how you install Ansible while running pipeline jobs or using an image that has Terraform and Ansible?