---
# CentOS related tasks

- name: install ancillaries packages
  dnf:
    name:
      - mariadb
      - python2-cryptography
      - mod_ssl
      - openssl
    state: latest
    enablerepo: epel

- name: Ensure Apache is installed on {{ ansible_facts['distribution'] }}
  dnf:
    name: httpd
    state: present
  when: websrv in ["apache", "apache2"]

- name: Set http env on {{ ansible_facts['distribution'] }}
  set_fact:
    http_service_name: httpd
    http_webroot: /var/www/html
    websrv_user: apache
    websrv_group: apache
  when: websrv in ["apache", "apache2"]

- name: Get httpd version
  shell: "httpd -v | head -n1 | cut -d'/' -f2 | cut -d' ' -f1"
  register: web_version
  when: websrv in ["apache", "apache2"]

- name: Get SSL version
  shell: "openssl version | cut -d' ' -f2 | cut -d'-' -f1"
  register: ssl_version

- name: Set web and SSL status
  set_fact:
    web_status: "{{ web_version.stdout|string is version('2.4.8', '>=') }}"
    ssl_status: "{{ ssl_version.stdout|string is version('1.1.1', '>') }}"

- name: Change apache configuration
  template:
    src: CentOS/httpd.conf.j2
    dest: /etc/httpd/conf.d/tune.conf
    owner: root
    group: root
    mode: '0644'
  when: websrv in ["apache", "apache2"]

- name: Allow http to listen on tcp port 80
  seport:
    ports: 80
    proto: tcp
    setype: http_port_t
    state: present

- name: Start {{ http_service_name }} service
  service:
    name: "{{ http_service_name }}"
    state: started
