Re: [ansible-devel] Content from multiple hosts to one file

2018-03-08 Thread Ed C
I think what you're after is the "magic" groups and hostvars variables:
http://docs.ansible.com/ansible/latest/playbooks_variables.html#magic-variables-and-how-to-access-information-about-other-hosts

These let you access the information about what hosts are in a group and
the facts about those hosts. Combining these with a loop using the template
module should give you what you want.

For example, lets assume you wanted to produce a list of the webservers in
your loadbalancer configuration. You could do something like


- hosts: loadbalancer
tasks:
- template:
src: mytemplate.j2
dest: list-of-hosts

Then the template file would look something like:

{% for host in groups['webservers'] %}
{{ hostvars[host]['ansible_hostname'] }}
{% endfor %}


What this is doing is looping over all the hosts in the webservers group,
then pulling out the ansible_hostname fact for each host. You can pull out
whatever fact it is you want from the other hosts.

Hope that helps
Ed
On Thu, 8 Mar 2018 at 3:39 AM, belajzus  wrote:

> Hi to all,
>
> I need to generate some file, and inside that file is some content from
> multiple hosts.
> I've done that using template module, so I generate one file on every
> host, delegate that to localhost, and with assemble module all that files I
> merge to one single file.
> Is that OK, or is it the better way to do the same.
> I try with blockinfile module, but it always override current content of
> some file, and I'm not sure is it possible to generate new file with
> blockinfile module.
> I would like to run playbook on the group, collect some data with custom
> facts, and those custom facts from all hosts use to populate one single
> file on control machine for example.
>
> Tnx for any help
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-devel+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-devel] Content from multiple hosts to one file

2018-03-07 Thread belajzus
Hi to all,

I need to generate some file, and inside that file is some content from 
multiple hosts.
I've done that using template module, so I generate one file on every host, 
delegate that to localhost, and with assemble module all that files I merge 
to one single file.
Is that OK, or is it the better way to do the same. 
I try with blockinfile module, but it always override current content of 
some file, and I'm not sure is it possible to generate new file with 
blockinfile module. 
I would like to run playbook on the group, collect some data with custom 
facts, and those custom facts from all hosts use to populate one single 
file on control machine for example.

Tnx for any help

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.