/home/travis/.ansible/roles/robertdebock.httpd/tasks/main.yml
---
# tasks file for httpd
- name: include assert.yml
  include_tasks: assert.yml
  run_once: yes

- name: install apache httpd
  package:
    name: "{{ httpd_packages }}"
    state: present

- name: modify selinux settings
  seboolean:
    name: "{{ item }}"
    state: yes
    persistent: yes
  when:
    - ansible_selinux.status is defined
    - ansible_selinux.status == "enabled"
  loop: "{{ httpd_sebooleans }}"

- name: allow connections to custom port
  seport:
    ports: "{{ item }}"
    proto: tcp
    setype: http_port_t
    state: present
  when:
    - ansible_selinux.status is defined
    - ansible_selinux.status == "enabled"
  loop:
    - "{{ httpd_port }}"
    - "{{ httpd_ssl_port }}"

- name: configure ssl
  template:
    src: ssl.conf.j2
    dest: "{{ httpd_config_directory }}/ssl.conf"
    mode: "0644"
  notify:
    - test httpd configuration validity
    - restart httpd

- name: configure locations
  template:
    src: location.conf.j2
    dest: "{{ httpd_config_directory }}/{{ item.name }}.conf"
    mode: "0644"
  loop: "{{ httpd_locations }}"
  notify:
    - test httpd configuration validity
    - restart httpd
  when:
    - httpd_locations is defined
  loop_control:
    label: "{{ item.name }}"

- name: configure vhosts
  template:
    src: vhost.conf.j2
    dest: "{{ httpd_config_directory }}/{{ item.name }}.conf"
    mode: "0644"
  loop: "{{ httpd_vhosts }}"
  notify:
    - test httpd configuration validity
    - restart httpd
  when:
    - httpd_vhosts is defined
  loop_control:
    label: "{{ item.name }}"

- name: configure httpd
  template:
    src: "{{ httpd_config_src }}"
    dest: "{{ httpd_config_dest }}"
    mode: "0644"
  notify:
    - test httpd configuration validity
    - restart httpd

- name: configure listening ports
  template:
    src: "{{ httpd_ports_conf }}.j2"
    dest: "{{ httpd_server_root }}/{{ httpd_ports_conf }}"
    mode: "0644"
  notify:
    - test httpd configuration validity
    - restart httpd
  when:
    - ansible_os_family == "Debian" or
      ansible_os_family == "Suse"

- name: configure redirect from http to https
  template:
    src: default_vhost.conf.j2
    dest: "{{ httpd_config_directory }}/default_vhost.conf"
    mode: "0644"
  notify:
    - test httpd configuration validity
    - restart httpd

- name: create docroot
  file:
    path: "{{ item.documentroot }}"
    state: directory
    mode: "0755"
  loop: "{{ httpd_vhosts }}"
  when:
    - httpd_vhosts is defined
    - item.documentroot is defined

- name: flush handlers
  meta: flush_handlers

- name: start and enable httpd
  service:
    name: "{{ httpd_service }}"
    state: started
    enabled: yes