Reputation: 487
I'm trying to fetch a file from a list of hosts in an inventory file, and then also from another host that has the same file on a different path.
I don't want to add this particular host on the inventory so I'm trying to manage it through the add_host
module to the in-memory inventory
The problem is that plays are executed only on the hosts from the inventory file, and ignoring the one I'm adding with add_host
.
My playbook:
---
- name: Play
hosts: localhost
vars:
file_to_fecth: "/home/user/filename"
dest_dir: "/tmp/"
tasks:
- name: add new host
add_host:
hostname: server.dns.name
groups: addedgroup
file_to_fecth: "/opt/dir/filename"
hosts: all:addedgroup
tasks:
- name: Fetching file
fetch:
src: "{{ file_to_fecth }}"
dest: "{{ dest_dir }}/{{ ansible_host }}_filename"
flat: yes
Upvotes: 1
Views: 1616
Reputation: 487
This is working, thanks to @β.εηοιτ.βε
---
- name: Play
hosts: localhost
tasks:
- name: add new host
add_host:
hostname: server.dns.name
groups: addedgroup
file_to_fecth: "/opt/dir/filename"
- name: Play
hosts: all:addedgroup
vars:
dest_dir: "/tmp/"
tasks:
- name: Fetching file
fetch:
src: "{{ file_to_fecth }}"
dest: "{{ dest_dir }}/{{ ansible_host }}_filename"
flat: yes
Upvotes: 1