---

- name: "Generate html file for each host"
  hosts: all
  gather_facts: yes
  vars:
    host_inventory: "central-inventory"
    inventory_dir:  "/var/www/html/inventory"
  tasks:
    - name: "Create template directory"
      file:
        path: "{{inventory_dir}}"
        owner: "apache"
        group: "apache"
        mode: "0755"
        state: "directory"
      # Delegate this execution on central machine
      delegate_to: "{{host_inventory}}"
      # As we only have one central machine,
      # run only one time this task
      run_once: yes
    - name: "html file generation"
      template:
        src: "machine.html.j2"
        dest: "{{inventory_dir}}/{{inventory_hostname}}.html"
      delegate_to: "{{host_inventory}}"
