0

I have a question on how do we give multiple values to "ansible_host" magic variable.

I have my hosts.yml like below:

all:
  hosts:
    ansible:
      host:
  children:
    applications:
      children:
        java_applications:
          children:
            atlassian_applications:
              hosts:
                confluence:
                  ansible_host: 53.31.54.55

i have requirement to specify multiple hosts to the ansible_host magic variable and perform all the tasks to all the hosts mentioned in my playbook file.

currently my playbook file is like below:

- hosts: confluence
  gather_facts: true
  become: true
  remote_user: root
  tasks:
  - debug: var=ansible_default_ipv4.address
  roles:
  - ansible-preparation
Anilkumar PVV
  • 49
  • 2
  • 10

1 Answers1

0

It's not possible

"to specify multiple hosts to the ansible_host magic variable"

Use groups to

"perform all the tasks to all the hosts mentioned in playbook file"

In your case for example the INI format would be

[confluence]
53.31.54.55
...
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
  • vladimir Botka: I think that will not work for me. Because i have confluence as my host_vars it will have some pre-defined vars that the script is using. If i start using the Ip's directly in the place of hosts my host_vars will not be picked up. --Hope you understand.? any other way around..? – Anilkumar PVV Mar 26 '19 at 07:41
  • Move your confluence.yml to group_vars/. Keep there the variables valid for all confluence installations. Create a host_vars/53.31.54.55.yml file with the vars valid only for that single host (using a fqdn for this name would be more readable). And take the time to [read the inventory manual in depthl](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html) to get more accustomed with the base concepts. – Zeitounator Mar 28 '19 at 20:05