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

Getting only one host ip #108

Open binaryArrow opened 2 months ago

binaryArrow commented 2 months ago

When I use the playbook resource and run following task:

 - name: debug
      debug:
        msg: "{{ groups['azure_nomad_vms'] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | join(',') }}"

which should give me a list of 3 ip addresses because I have 3 Host machines, it only gives me one. I use the ip's to set the server ip's in a nomad config file. I am using the playbook resource like this:

resource "ansible_playbook" "playbook" {
  count      = var.vm_number
  playbook   = "../ansible/playbook.yml"
  name       = azurerm_public_ip.this[count.index].ip_address
  replayable = true
  groups     = ["azure_nomad_vms"]
  extra_vars = {
    ansible_user                 = ansible_host.this[count.index].variables.ansible_user
    ansible_ssh_private_key_file = ansible_host.this[count.index].variables.ansible_ssh_private_key_file
    ansible_python_interpreter   = "/usr/bin/python3"
  }
}

output "ansible_playbook_stdout" {
  value = ansible_playbook.playbook[*].ansible_playbook_stdout
}

Using a null_resource with local_exec works, but I would rather prefer using the playbook resource