dynamic inventory jinja2 template help

I have nodes in AWS and I’d like to use the dynamic inventory to create a template. Currently I cant get the facts from all the nodes into the one template file. The template only gets populated with the node thats in “role deploy” and doesnt include the monitor group.

playbook ---------

  • name: Gather facts
    ec2_remote_facts:
    ec2_region: us-east-1
    filters:
    instance-state-name: running
    “tag:Role”: monitor
    become: false
    register: ec2

  • name: Deploy host template
    template: src=filename dest=filename
    when: “‘tag_Role_deploy’ in group_names”

jinja2 template-------------

{% for host in groups[‘tag_Name_monitor’] %}

{{ host }}

{% endfor %}

Thanks

Try something like this https://github.com/f500/ansible-dumpall to understand what you have.