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

Getting only one host ip #108

Open
binaryArrow opened this issue Apr 15, 2024 · 0 comments
Open

Getting only one host ip #108

binaryArrow opened this issue Apr 15, 2024 · 0 comments

Comments

@binaryArrow
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants