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

ansible_playbook always running playbook or running it only for the first time regardless system drift #77

Open mkkot opened 5 months ago

mkkot commented 5 months ago

Hello!

resource "ansible_playbook" "timer" {
  for_each = toset(fileset(path.module, "*/systemd/*.timer"))

  playbook   = "playbooks/timer.yaml"
  name       = "nas"

  extra_vars = {
    script_name = split("/", each.key)[0]
    hosts = "192.168.0.111"
  }
  depends_on = [ system_file.timer ]
}

Now, on every plan or apply the resource is "created", meaning the plan shows as if the resource was not existing.

We can set replayable as false, but then running terraform plan or apply doesn't revert the state of the timer, if for some reason its state was altered manually on the system.

I think this is against terraform's spirit. I can understand that provider is maybe not exactly capable of displaying detailed drift of the resources it manages, but here's the bare minimum I would expect:

ansible-playbook --check should be run in terraform plan mode.

Desired state

Case in terraform plan:

Case in terraform apply:

Currently what happens:

(with default replayable = true)

Case in terraform plan:

Case in terraform apply: