VNC Configuration using Ansible in CentOS 6


1. Install epel repo on CentOS 6 system:

    # yum install epel-release  -y

2. Install ansible using yum:

    # yum install ansible  -y

3. Go to the '/etc/ansible/roles' directory and run the below command to create the required directory structure:

    # ansible-galaxy  init  vnc6  --offline
       - vnc6 was created successfully
  # tree vnc6
   
   vnc6
    ├── defaults
    │   └── main.yml
    ├── files
    ├── handlers
    │   └── main.yml
    ├── meta
    │   └── main.yml
    ├── README.md
    ├── tasks
    │   └── main.yml
    ├── tests
    │   ├── inventory
    │   └── test.yml
    └── vars
        └── main.yml    

4. Create the service file 'vncservers' in '/etc/ansible/roles/vnc6/files/' to allow 'root' user to access the vncserver using port 5901:

    # cat  vncservers
       
    VNCSERVERS="1:root"
    VNCSERVERARGS[1]="-geometry 1200x1000"

5. Modify the 'main.yaml' file in '/etc/ansible/roles/vnc6/tasks' directly with the following content:

---
# tasks file for vnc6
- name: "Installing VNC Package"
  yum: pkg={{ item }} state=installed
  with_items:
  - tigervnc-server

- name: "Copying the vnc configuration file"
  copy: src="/etc/ansible/roles/vnc6/files/vncservers" dest="/etc/sysconfig/vncservers" owner=root group=root mode=0644

- name: "Create the remote /root/.vnc directory"
  file:
    path: /root/.vnc
    mode: 0755
    state: directory

- name: "Generate vnc password for root user remotely"
  shell: |
      echo RedHat123! | vncpasswd  -f  >  /root/.vnc/passwd

- name: "Change the permission to 600 for /root/.vnc/passwd file"
  file:
    path: /root/.vnc/passwd
    mode: 0600

- name: "Start & enable the vncserver service"
  service: name=vncserver state=started enabled=yes

6. Make a file with 'site.yaml' name and mention which role need to be called from the roles directory to validate the syntax and deploy the changes in the target system:

---
  - hosts: host1.example.com
    roles:
      - vnc6

    # ansible-playbook  ~/site.yaml  -syntax-check

       playbook: site.yaml

7. Configure the passwordless SSH to client system from ansible provision server:

    # ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
ce:7d:fd:65:4e:61:4e:a9:09:61:90:d2:75:1b:d1:1d root@server.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|        ..o. +oEo|
|       . o. . o..|
|        .  o .   |
|          . .   .|
|        S  .   = |
|       o .  ..* .|
|        o . .o..+|
|           .   =.|
|                o|
+-----------------+

8. Copy the ssh public key to the client system using the below command:

  # ssh-copy-id -i /root/.ssh/id_rsa.pub root@hots1.example.com

9. Run the playbook with all required changes:

    [root@server ~] # ansible-playbook  ~/site.yaml

PLAY [host1.example.com] 
*********************************************************************************

TASK [Gathering Facts] 
*********************************************************************************
ok: [host1.example.com]

TASK [vnc6 : Installing VNC Package] 
*********************************************************************************
changed: [host1.example.com] => (item=[u'tigervnc-server'])

TASK [vnc6 : Copying the vnc configuration file] 
*********************************************************************************
changed: [host1.example.com]

TASK [vnc6 : Create the remote /root/.vnc directory] 
*********************************************************************************
changed: [host1.example.com]

TASK [vnc6 : Generate vnc password for root user remotely] 
*********************************************************************************
changed: [host1.example.com]

TASK [vnc6 : Change the permission to 600 for /root/.vnc/passwd file] *********************************************************************************
changed: [host1.example.com]

TASK [vnc6 : Start & enable the vncserver service] 
*********************************************************************************
changed: [host1.example.com]

PLAY RECAP 
*********************************************************************************
host1.example.com            : ok=7    changed=6    unreachable=0    failed=0

10. VNC server configuration is complete on 'host1.example.com' and can be accessed using 'root/RedHat123' credentials over 5901 port.



Comments

Popular posts from this blog

How to build Ubuntu Server 20.04 LTS OVA with vAPP Properties ?

VNC Configuration using Ansible in CentOS 7

[RHOSP] Red Hat Openstack 11 Deployment on Nested KVM Infrastructure