I have this playbook:
---
- hosts: all
tasks:
- command: echo {{ item }}
with_items: [ item1forhost1, item2forhost2]
This results in:
TASK [command] *****************************************************************
changed: [host1] => (item=item1forhost1)
changed: [host2] => (item=item1forhost1)
changed: [host1] => (item=item2forhost2)
changed: [host2] => (item=item2forhost2)
Every host is reading the same line, where as I want host1 to read itemfforhost1 and host2 to read item2forhost2. How can this be done? I'm looking for something like this:
TASK [command] *****************************************************************
changed: [host1] => (item=item1forhost1)
changed: [host2] => (item=item2forhost2)
Following up on @techraf’s solution, here is what you can do. In your ansible directory, create a directory called
host_vars
. Underneath that directory, create two files calledhost1.yml
andhost2.yml
. Inhost1.yml
put:And in
host2.yml
put:Now in your playbook, you can write: