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

Provider Configuration Documentation (StrictHostKeyChecking=no) #121

Open alexandrud opened 2 months ago

alexandrud commented 2 months ago

Hi,

Are there no configuration options for the Ansible provider? In my case, since I'm working on a proof of concept, I re-build a VM with the same IP several times. Since the key for the host changes, the playbook fails. I looked around for documentation on provider configuration options, but could not find anything. It would be nice to be able to set options for the provider from the configuration block. Maybe follow the ansible.cfg structure: https://docs.ansible.com/ansible/latest/reference_appendices/config.html

provider "ansible" {
  defaults {
     host_key_checking = false
  }
  galaxy {
     server = "some.server.com"
  }
  persistent_connection {
     command_timeout = 30
  }
}
alexandrud commented 1 month ago

Apparently ansible does offer a way to do this at runtime. It has a couple of variables to manipulate this. I ended up with:

resource "ansible_playbook" "playbook" {
  for_each   = toset(var.ansible_playbooks)
  playbook   = each.key
  name       = vsphere_virtual_machine.vm.default_ip_address
  replayable = var.ansible_replayable
  tags       = var.ansible_tags
  verbosity  = var.ansible_verbosity
  extra_vars = {
    ansible_ssh_host_key_checking = var.ansible_ssh_host_key_checking
  }
}