- block:
  - name: include vault
    ansible.builtin.include_vars:
      file: jaydee.yml
  - name: Install vnc packages
    ansible.builtin.apt:
      name: 
        - tigervnc-standalone-server
        - tigervnc-common
      update_cache: yes

  - name: Creating config
    become: true
    ansible.builtin.copy:
      
      dest: "/etc/systemd/system/vncserver@.service"
      content: |
        [Unit]
        Description=VNC Server
        After=syslog.target network.target
        [Service]
        Type=forking
        WorkingDirectory=/home/jd
        User=jd
        Group=jd
        ExecStartPre=/bin/sh -c '/usr/bin/tigervncserver -kill %i > /dev/null 2>&1 || :'
        ExecStart = /usr/bin/tigervncserver -xstartup /usr/bin/mate-session -SecurityTypes VncAuth,TLSVnc -geometry 1600x900 -localhost no %i
        ExecStop = /usr/bin/tigervncserver -kill %i
        Environment="HOME=/home/jd"
        [Install]
        WantedBy=multi-user.target
      owner: root
      mode: '0744'
  - name: Create a directory if it does not exist
    ansible.builtin.file:
      path: /home/jd/.vnc
      state: directory
      mode: '0700'
      owner: jd
      group: jd
  - name: Set vnc password
    ansible.builtin.shell: 
      cmd: echo  "{{ vnc_password }}" | vncpasswd -f > /home/jd/.vnc/vncpasswd
  - name: Set vnc password
    ansible.builtin.shell: 
      cmd: echo  "{{ vnc_password }}" | vncpasswd -f > /home/jd/.vnc/passwd
  - name: Restart service vncserver, in all cases
    ansible.builtin.service:
      name: vncserver@:1
      state: restarted
      daemon-reload: true
      enabled: true
  become: true