Files
ansible.role.vncserver/tasks/main.yml
T
2019-01-22 16:58:51 +08:00

88 lines
2.5 KiB
YAML

- name: Install EPEL repo
yum:
name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
state: installed
# This environment group is tested on RHEL7 only
# See https://docs.ansible.com/ansible/latest/modules/yum_module.html#notes for package group vs environment group
#
- name: Install Server with GUI package group, may take a while...
yum:
name: '@^Server with GUI'
state: latest
- name: Install vncserver
yum:
name:
- tigervnc-server
- xterm
- xorg-x11-xauth
- cinnamon
state: latest
- name: Create .vnc directory
file:
path: "~{{vncuser}}/.vnc"
state: directory
mode: 0755
- name: Create vncpassword
shell: "echo {{vncpass}} | vncpasswd -f > ~{{vncuser}}/.vnc/passwd"
- name: Create xstartup file
copy:
dest: "~{{vncuser}}/.vnc/xstartup"
content: |
#!/bin/bash
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
#. /etc/X11/xinit/xinitrc
/bin/cinnamon-session
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
- name: Change ownership of .vnc
file:
path: "~{{ vncuser }}/.vnc"
owner: "{{ vncuser }}"
recurse: yes
- name: Change perm of passwd file
file:
path: "~{{ vncuser }}/.vnc/passwd"
mode: 0600
- name: Create systemd config
copy:
dest: /etc/systemd/system/vncserver@:1.service
content: |
[Unit]
Description=Remote desktop service (VNC)
After=syslog.target network.target
[Service]
Type=forking
User={{vncuser}}
PIDFile=/home/%u/.vnc/%H%i.pid
ExecStartPre=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
ExecStart=/usr/bin/vncserver %i
ExecStop=/bin/sh -c '/usr/bin/vncserver -kill %i > /dev/null 2>&1 || :'
[Install]
WantedBy=multi-user.target
- name: Start and enable vncserver
service:
name: vncserver@:1
state: started
enabled: yes
- name: Display vncpass
debug:
var: vncpass