0
votes

I have four different hosts. host1, host2, host3, host4

I am trying to update following files on the these hosts.

host1
/var/www/foo1

host2
/var/www/foo1
/var/tmp/foo1

host3
/var/www/foo1

host4
/var/tmp/foo1

I am able to write two different playbook with different inventory files and group vars to achieve this task.

Inventory file 1

[group_foo1]
host1
host2
host3

Group variable

File name: group_foo1

path:/var/www

Inventory file 2

[group_foo2]
host2
host4

Group variable

File name: group_foo2

path:/var/tmp

Task

name: copy the file
copy: src=foo1 dest={{path}}

I want to do this task using single playbook.

How it can be done?

1
Setup a vars file to include in your playbook. docs.ansible.com/ansible/index.html is a great resource - Coder-guy

1 Answers

2
votes

You should use synchronize module:

# Synchronize two directories on one remote host.
synchronize:
    src: /first/absolute/path
    dest: /second/absolute/path
delegate_to: "{{ inventory_hostname }}"

ALso you can try to iterate in a tasks over all hosts:

with_items: groups['all']