---
# Originally I tried adding to the www group, but because Ansible uses one SSH
# connection, that broke the initial provisioning, since groups aren't refreshed
# without a new session or log off/log on.
- name: Ensure necessary groups exist.
  group: "name={{ item }} state=present"
  with_items:
    - admin
    - dialout

- name: Ensure vagrant user is in admin group.
  user: "name={{ vagrant_user }} append=yes groups=admin"

- name: Ensure www-data user is in dialout group (Debian).
  user: "name=www-data append=yes groups=dialout"
  when: ansible_os_family == 'Debian'

- name: Set nicer permissions on Apache log directory.
  file:
    path: "/var/log/{{ apache_daemon }}"
    state: directory
    mode: 0755
    recurse: true
  when: drupalvm_webserver == 'apache'

- name: Copy Nginx vhosts into place.
  template:
    src: ../templates/nginx-vhost.conf.j2
    dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
    force: yes
    owner: root
    group: root
    mode: 0644
  with_items: "{{ nginx_hosts }}"
  notify: restart nginx
  when: drupalvm_webserver == 'nginx'
