]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/add_apache_vhost/tasks/main.yml
Feat(apache): Install and configure Apache; add a virtual host
[ansible.git] / playbooks / debian / roles / add_apache_vhost / tasks / main.yml
diff --git a/playbooks/debian/roles/add_apache_vhost/tasks/main.yml b/playbooks/debian/roles/add_apache_vhost/tasks/main.yml
new file mode 100644 (file)
index 0000000..d5f9ddd
--- /dev/null
@@ -0,0 +1,33 @@
+- name: Check vhost
+  command: "test -L /etc/apache2/sites-enabled/{{ virtual_host }}.conf"
+  failed_when: false
+  register: vhost
+  changed_when: vhost.rc != 0
+
+- name: Configure site
+  become: true
+  template:
+    src: vhost.conf
+    dest: "/etc/apache2/sites-available/{{ virtual_host }}.conf"
+    owner: root
+    group: root
+    mode: '0640'
+    force: no
+  notify: Reload apache
+  when: vhost.rc != 0
+
+- name: Enable site
+  become: true
+  command: "a2ensite {{ virtual_host }}"
+  notify: Reload apache
+  when: vhost.rc != 0
+
+- name: Create log directory
+  become: true
+  file:
+    path: /var/log/apache2/{{ virtual_host }}
+    state: directory
+    owner: root
+    group: root
+    mode: '0640'
+  when: vhost.rc != 0