---
# https://github.com/geerlingguy/drupal-vm/issues/247#issuecomment-153295035
- name: 'Prevent an error of setting ownership for "/var/www/html.dpkg-new"'
  file:
    path: "/var/www/html"
    state: "{{ item }}"
  with_items: ["absent", "directory"]

- name: Purge configs
  apt:
    name: apache2
    purge: yes

- name: Remove installation directory
  file:
    path: "{{ cikit_apache.dest }}"
    state: absent

- name: Purge components
  shell: |-
    apt autoremove {{ item }} --purge -y
    apt install {{ item }} -y --force-yes
  with_items: ["apache2-bin", "apache2-data"]

- name: Reinstall
  apt:
    name: "{{ item }}"
    state: installed
  with_items: ["apache2", "apache2-utils"]

- name: Ensure that necessary ports free and processes stopped
  shell: "kill $(sudo lsof -t -i:{{ item }}) > /dev/null 2>&1"
  args:
    executable: /bin/bash
  ignore_errors: yes
  with_items: ["{{ apache_port }}", "{{ apache_port_ssl }}"]

---
# https://github.com/geerlingguy/drupal-vm/issues/247#issuecomment-153295035
- name: 'Prevent an error of setting ownership for "/var/www/html.dpkg-new"'
  file:
    path: "/var/www/html"
    state: "{{ item }}"
  with_items: ["absent", "directory"]

- name: Purge configs
  apt:
    name: apache2
    purge: yes

- name: Remove installation directory
  file:
    path: "{{ cikit_apache.dest }}"
    state: absent

- name: Purge components
  shell: |-
    apt autoremove {{ item }} --purge -y
    apt install {{ item }} -y --force-yes
  with_items: ["apache2-bin", "apache2-data"]

- name: Reinstall
  apt:
    name: "{{ item }}"
    state: installed
  with_items: ["apache2", "apache2-utils"]

- name: Ensure that necessary ports free and processes stopped
  shell: "lsof -ti:{{ item }} | xargs kill"
  ignore_errors: yes
  with_items: ["{{ apache_port }}", "{{ apache_port_ssl }}"]

Simplify killing processes on ports
[Apache] Simplify killing processes on ports
