---

- name: vnc directory
  file:
    path: ~/.vnc
    state: directory
    mode: 0700

- name: vnc config
  template:
    src: vnc/config.j2
    dest: ~/.vnc/config
    mode: 0644

- name: vnc env
  template:
    src: vnc/vncserver.env.j2
    dest: ~/.vnc/vncserver.env
    mode: 0644

- name: vnc server config
  template:
    src: vnc/vnc.conf.j2
    dest: ~/.vnc/vnc.conf
    mode: 0644

- name: vnc passwd
  copy:
    content: "{{ lookup('pipe','pwgen 24 1' )}}"
    dest: ~/.vnc/passwd
    mode: 0600
    force: no

- name: fetch vnc passwd
  fetch:
    src: ~/.vnc/passwd
    dest: ~/.vnc/passwd.{{inventory_hostname}}
    flat: yes

- name: copy vnc passwd files
  copy:
    src: ~/.vnc/passwd.{{item}}
    dest: ~/.vnc/passwd.{{item}}
  with_items: "{{ home_access_to_hosts }}"

- name: default vnc client options
  template:
    src: vnc/default.tigervnc.j2
    dest: ~/.vnc/default.tigervnc
    mode: 0755

- name: vncserver user service
  template:
    src: vnc/vncserver.service.j2
    dest: ~/.config/systemd/user/vncserver@.service
  notify: systemd daemon-reload

- name: Xvnc-session script
  template:
    src: vnc/Xvnc-session.j2
    dest: ~/.vnc/Xvnc-session
    mode: 0755

- name: vnc xsession script
  template:
    src: vnc/xsession.j2
    dest: ~/.vnc/xsession
    mode: 0755
