Split `tasks/main` into `tasks/add_vhost`.
--- /dev/null
+- 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 directories
+ become: true
+ file:
+ path: "{{ item }}/{{ virtual_host }}"
+ state: directory
+ owner: root
+ group: www-data
+ mode: '0755'
+ loop: ['/usr/local/apache2/cgi-bin', '/usr/local/apache2/htdocs',
+ '/var/log/apache2',
+ ]
+ when: vhost.rc != 0
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
+- name: Add vhost
+ import_tasks: add_vhost.yml
when: vhost.rc != 0
-- name: Enable site
- become: true
- command: "a2ensite {{ virtual_host }}"
- notify: Reload apache
- when: vhost.rc != 0
-
-- name: Create directories
- become: true
- file:
- path: "{{ item }}/{{ virtual_host }}"
- state: directory
- owner: root
- group: www-data
- mode: '0755'
- loop: ['/usr/local/apache2/cgi-bin', '/usr/local/apache2/htdocs',
- '/var/log/apache2',
- ]
when: vhost.rc != 0