---

- name: "Apache installation"
  hosts: inventaire
  tasks:
    - name: "Apache package installation"
      yum:
        name: "httpd"
        state: "present"
    - name: "Apache configuration"
      template:
        src: "inventory.conf.j2"
        dest: "/etc/httpd/conf.d/inventory.conf"
        owner: "apache"
        group: "apache"
      # register execution result for template creation
      register: apache_conf
    # debug instruction to get apache_conf content
    - debug: var=apache_conf
    - name: "Restart apache service"
      service:
        name: "httpd"
        state: "restarted"
      # restart if necessary
      when: apache_conf.changed
    - name: "Start apache service"
      service:
        name: "httpd"
        state: "started"
        enabled: yes
