Ansible inventroy report

# ./group_vars/example.com/hosts.yml
---
SERVER:
  www02.example.com:
    alias: www2.example.com
    type: phy
    nic:
      eth0:
        mac: 00:00:00:57:82:4c
        ip: 10.100.0.30
        nat: 10.99.0.188
      eth1:
        mac: 00:00:00:bc:88:52
        ip: 192.168.100.101
      bmc:
        mac: 00:00:00:51:aa:1e
        ip: 10.100.0.201
        pass: pass1234
    gateway: 10.100.0.254
  db01.example.com:
    alias: db1.example.com
    type: lxc
    nic:
      eth0:
        mac: 00:00:00:55:29:70
        ip: 10.100.0.32
        nat: 10.99.0.189
      eth3:
        mac: 00:00:00:bc:88:60
        ip: 192.168.100.100
      bmc:
        mac: 00:00:00:51:05:dc
        ip: 10.100.0.202
        pass: changeme
    gateway: 10.100.0.254
 
DNS:
  proxy01.example.com:
    type: dns
    nic:
      eth0:
        mac: 00:00:00:00:01:10
        ip: 10.100.0.200
        nat: 10.99.0.219
    gateway: 10.100.0.254
 
OFFLINE:
  www10.example.com:
    type: kvm
    nic:
      eth0:
        mac: 00:00:00:69:37:21
        ip: 10.10.0.111
        nat:
    gateway: 10.100.0.1
 
 
# report_hosts.yml
- hosts: localhost
  vars:
    output_file: /tmp/output.csv
  tasks:
    - name: Generate {{ output_file }}
      copy:
        content: |
          Host,IP,Gateway,NAT,MAC,Type
          {% for key, value in (SERVER | combine(DNS) | combine(OFFLINE)).iteritems() | sort %}
          {% if value.nic.eth0.nat is defined %}
          {{ key }},{{ value.nic.eth0.ip }},{{ value.gateway }},{% if value.nic.eth0.nat is defined %} {{ value.nic.eth0.nat }}{% endif %},{% if value.nic.eth0.mac is defined %} {{ value.nic.eth0.mac }}{% endif %},{{ value.type }}
          {% endif %}
          {% endfor %}
        dest: "{{ output_file }}"