--- /dev/null
+- 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