---
- name: Update script in place
  template:
    src: templates/update.j2
    dest: "/home/{{ item }}/bin/update"
    mode: 0755
    owner: "{{ item }}" 
    group: "{{ item }}" 
  with_items: "{{ users }}"

- name: Git config in place
  template:
    src: templates/gitconfig.j2
    dest: "/home/{{ item }}/.gitconfig"
    mode: 0644
    owner: "{{ item }}" 
    group: "{{ item }}"
  with_items: "{{ users }}"

- name: .htaccess file in place
  copy:
    src: files/htaccess
    dest: "/home/{{ item }}/sites/web/.htaccess"
    mode: 0644
    owner: "{{ item }}" 
    group: "{{ item }}"
  with_items: "{{ users }}"

- name: Uploads tgz creation cron in place 
  cron:
    name: "Create tgz of uploads"
    minute: "01"
    hour: "09"
    user: "{{ item }}"
    job: "cd /home/{{ item }}/sites/web ; tar -zcf cotech-images.tgz app/uploads/"
  with_items: "{{ users }}"

- name: Cron script in place
  template:
    src: templates/cron.j2
    dest: "/home/{{ item }}/bin/cron"
    mode: 0755
    owner: "{{ item }}" 
    group: "{{ item }}"
  with_items: "{{ users }}"

- name: Crontab in place
  cron:
    name: "Update code"
    minute: "*"
    hour: "*"
    user: "{{ item }}"
    job: "/home/{{ item }}/bin/cron"
  with_items: "{{ users }}"

- name: favicon.ico file in place
  copy:
    src: files/favicon.ico
    dest: "/home/{{ item }}/sites/web/favicon.ico"
    mode: 0644
    owner: "{{ item }}" 
    group: "{{ item }}"
  with_items: "{{ users }}"

- name: ~/bin in PATH
  lineinfile:
    regexp: '^export\ PATH='
    line: 'export PATH="$PATH:$HOME/bin"'
    dest: "/home/{{ item }}/.bashrc"
    state: present
  with_items: "{{ users }}"

- name: Live database dumped
  shell: "mysqldump cotech > /home/cotech/private/cotech.sql"

- name: Dev database overwritten with live data
  shell: "cat /home/cotech/private/cotech.sql | mysql cotechdev"

- name: Live files rsynced to dev
  command: "rsync -aq --chown=cotechdev:cotechdev --chmod=D2775,F0664 /home/cotech/sites/web/app/uploads/ /home/cotechdev/sites/web/app/uploads/"
