ansible / terraform-provider-ansible

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

Playbook args dont change when updating the ressource #31

Open d-strobel opened 1 year ago

d-strobel commented 1 year ago

Description: I encountered an issue while using the ressource ansible_playbook. When attempting to set new or different extra variables to the resource after the first apply, the modification does not take effect as I expected. Instead, only the variables specified at the first run are present in the args output.

Steps to Reproduce: Define the ansible_playbook resource with replayable set to false. Initially specify only one extra variable, for example: test_1 = "test1" and apply. Then create a second variable, for example test_2 = "test2" Apply the Terraform configuration to update the infrastructure.

resource "ansible_playbook" "playbook" {
  playbook   = "playbook.yml"
  name       = "localhost"
  replayable = false

  extra_vars = {
    test_1 = "test1"
    test_2 = "test2"
  }
}
output "test" {
  value = ansible_playbook.playbook.args
}

Expected Behavior: When modifying the ansible_playbook resource to include the additional extra variable, I expect the modification to properly add the new variable to the playbook arguments.

test = tolist([
  "-e",
  "hostname=localhost",
  "-e",
  "test_1=test1",
 "-e",
  "test_2=test2",
  "playbook.yml",
])

Actual Behavior: Despite adding the new extra variable to the extra_vars block, only the first variable (test_1) is shown and passed to the playbook. The new variable (test_2) does not take effect and is not applied during the playbook execution.

test = tolist([
  "-e",
  "hostname=localhost",
  "-e",
  "test_1=test1",
  "playbook.yml",
])

Additional Information: Terraform provider version: 1.1.0 Ansible version: 2.14.1

I appreciate your assistance in resolving this issue. Let me know if any further information is needed.

abikouo commented 5 months ago

@gravesm this issue is reproducible, but I am wondering if this is not expected. The playbook resource is created with replayable=false, this means it will be executed once, and later when we update the extra vars we cannot just save them into the state knowing that the play was not executed with these new variables. Should we execute the playbook when the extra vars have changed even if it is configured with replayable=false ? WDYT

gravesm commented 5 months ago

The description for the replayable attribute is kind of vague. I think this attribute should ultimately be deprecated and replaced by a triggers attribute that's just an arbitrary set of key/value pairs. This would give the user more flexibility to determine when to rerun, and would allow us to treat the playbook resource in a more familiar terraform fashion.

Jurka007 commented 1 month ago

Just went down this rabbit hole. It appears that with the replayable = false the playbook is executed on the resource change only, but with the arguments of the first play (the actual "args" does not change). If set to true it runs on every apply regardless if the resource was changer or not but the "args" gets updated. Can the replayable = false run only on the resource changes? Or what's the idea here?