I haven't used it myself, but I've been reading up on Salt quite a bit in hopes that I can replace Chef with it soon.
Stop by the list if you'd like more info, but it's easy to generate nagios configs from templates this way.
But yes, it's easy to do that. Assuming you meant a template, you could do:
{% for host in groups["datacenterX"] %} {% if host in groups["Y"] %} {{ ssh_host_key_rsa_public }} {% end if %} {% endif %}
Ansible is also good at carving up groups based on these things, like if you just wanted to talk to those hosts:
hosts: datacenterX:&Y
note that Hacker News ate my newlines.
etc
If you want to edit the post to include them, indent by at least four spaces the text for which newlines are important. Maybe like this:
{% for host in groups["datacenterX"] %}
{% if host in groups["Y"] %}
{{ ssh_host_key_rsa_public }}
{% end if %}
{% endif %} [sic]What happens if the server crashes? Can a subsequent run before all the data is repopulated cause the derived files to have invalid or missing data?
When you run again it gathers all the facts from the hosts.
This video is a nice introduction: http://m.youtube.com/watch?v=jJJ8cfDjcTc