Copy host inventory in file

21 views
Skip to first unread message

blue fox

unread,
Nov 26, 2020, 11:58:48 PM11/26/20
to Ansible Project
Hello,

How to put each host each time in file

example:

hosts file:

[webservers]

host1

hos2


----------


i would to copy each time running playbook  each host in file.txt


thank you

Vladimir Botka

unread,
Nov 27, 2020, 1:25:33 AM11/27/20
to blue fox, ansible...@googlegroups.com
On Thu, 26 Nov 2020 20:58:48 -0800 (PST)
blue fox <foxb...@gmail.com> wrote:

> I would to copy each time running playbook each host in file.txt

Is this what you're looking for ?

- shell: "echo {{ item }} >> file.txt"
loop: "{{ ansible_play_hosts_all }}"
run_once: true
delegate_to: localhost

FWIW, you can improve the log by prepending the date

- block:
- command: date
register: result
- shell: "echo {{ result.stdout}} {{ item }} >> file.txt"
loop: "{{ ansible_play_hosts_all }}"
run_once: true
delegate_to: localhost

--
Vladimir Botka

blue fox

unread,
Nov 27, 2020, 2:19:21 AM11/27/20
to Ansible Project

Thank you, but i need to copy each time one host

Example: 

- First execution of playbook : copy host1

- second execution of playbook : copy host2 


Thank you

blue fox

unread,
Nov 27, 2020, 4:05:25 AM11/27/20
to Ansible Project
how to create a template jinja for copy hosts of static inventory
Reply all
Reply to author
Forward
0 new messages