Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mkkot opened this issue Jan 24, 2024 · 0 comments
Labels
type/enhancement New feature or request

Comments

@mkkot
Copy link

mkkot commented Jan 24, 2024

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:

  • resource state has changed: there should be an information in the plan that the resource will be replaced.
  • resource doesn't exist: there should be an information in the plan that the resource will be created.
  • resource has not changed: the plan should indicate no changes to this resource

Case in terraform apply:

  • resource state has changed: run the playbook
  • resource doesn't exist: run the playbook
  • resource has not changed: do not run the playbook

Currently what happens:

(with default replayable = true)

Case in terraform plan:

  • resource state has changed: resource will be "Created"
  • resource doesn't exist: resource will be "Created"
  • resource has not changed: resource will be "Created"

Case in terraform apply:

  • resource state has changed: resource will be "Created"
  • resource doesn't exist: resource will be "Created"
  • resource has not changed: resource will be "Created"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants