Skip to content

Commit

Permalink
feat: check apache config before restart
Browse files Browse the repository at this point in the history
closes #11
  • Loading branch information
franklinkim committed Oct 12, 2020
2 parents 1b8cb18 + 333b17c commit 3f08a58
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
8 changes: 8 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
---

- name: test and restart apache2
command: apache2ctl configtest
notify: restart apache2

- name: test and reload apache2
command: apache2ctl configtest
notify: reload apache2

- name: restart apache2
service: name=apache2 state=restarted
when: apache2_service_state != 'stopped'
Expand Down
2 changes: 1 addition & 1 deletion tasks/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
owner: root
group: root
mode: "0644"
notify: reload apache2
notify: test and reload apache2
with_items:
- etc/apache2/apache2.conf
- etc/apache2/ports.conf
Expand Down
4 changes: 2 additions & 2 deletions tasks/manage_confs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
creates: "/etc/apache2/conf-enabled/{{ item.id }}.conf"
when: item.state is not defined or item.state != 'absent'
with_items: "{{ apache2_confs }}"
notify: reload apache2
notify: test and reload apache2

- name: Disabling conf
command: >
Expand All @@ -16,4 +16,4 @@
removes: "/etc/apache2/conf-enabled/{{ item.id }}.conf"
when: item.state is defined and item.state == 'absent'
with_items: "{{ apache2_confs }}"
notify: reload apache2
notify: test and reload apache2
2 changes: 1 addition & 1 deletion tasks/manage_default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
file:
dest: /etc/apache2/sites-enabled/000-default.conf
state: absent
notify: reload apache2
notify: test and reload apache2
when: apache2_remove_default

- name: Removing default host
Expand Down
4 changes: 2 additions & 2 deletions tasks/manage_modules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
creates: "/etc/apache2/mods-enabled/{{ item.id }}.load"
when: item.state is not defined or item.state != 'absent'
with_items: "{{ apache2_modules }}"
notify: reload apache2
notify: test and reload apache2

- name: Disabling modules
command: >
Expand All @@ -16,4 +16,4 @@
removes: "/etc/apache2/mods-enabled/{{ item.id }}.load"
when: item.state is defined and item.state == 'absent'
with_items: "{{ apache2_modules }}"
notify: reload apache2
notify: test and reload apache2
7 changes: 4 additions & 3 deletions tasks/manage_sites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- name: Creating webroots
file:
dest: "{{ apache2_sites_basedir }}/{{ item.id }}/htdocs"
mode: "0755"
state: directory
when: item.add_webroot is defined and item.add_webroot
with_items: "{{ apache2_sites }}"
Expand All @@ -15,7 +16,7 @@
group: root
mode: "0644"
with_items: "{{ apache2_sites }}"
notify: reload apache2
notify: test and reload apache2

- name: Enabling sites
file:
Expand All @@ -24,12 +25,12 @@
state: link
when: item.state is not defined or item.state == 'present'
with_items: "{{ apache2_sites }}"
notify: reload apache2
notify: test and reload apache2

- name: Disabling sites
file:
src: "/etc/apache2/sites-enabled/{{ item.id }}.conf"
state: absent
when: item.state is defined and item.state == 'absent'
with_items: "{{ apache2_sites }}"
notify: reload apache2
notify: test and reload apache2

0 comments on commit 3f08a58

Please sign in to comment.