Using Ansible to install vmware tools (open-vm-tools)

By | 1st August 2015

Installation of vmware tools for linux versions can be done using the open-vm-tools.

Noticed the below message while trying to install vmware tools on my Ubuntu 14.04


$ sudo ./vmware-install.pl
[sudo] password for rsa:
open-vm-tools are available from the OS vendor and VMware recommends using
open-vm-tools. See http://kb.vmware.com/kb/2073803 for more information.
Do you still want to proceed with this legacy installer? [no] no
$


Since Ansible was something I was trying out, thought of using the same to install vmware open tools.

Please see my earlier posts on getting started with ansible.

http://virtualtraces.com/2015/04/starting-with-ansible-devops/

Steps:
1. Create a folder(just for ease)

Added both the playbook and hosts file.
A simple playbook was created to help with the installation of the packages.


$ ls -ltr

total 8
-rw-rw-r– 1 rsa rsa 194 Aug 1 16:15 vmwtools.yml
-rw-r–r– 1 rsa rsa 434 Aug 1 16:15 hosts
$


$ cat vmwtools.yml

– hosts: ubuntu_vms
vars:
remote_user: stack
sudo: yes

tasks:
– name: Install vmware tools
apt:
name=open-vm-tools-desktop
state=latest
update_cache=yes
$


2. Try to see if the vm is pingable before starting with the installation.

$ ansible all -m ping -i hosts -k
SSH password:
192.168.0.9 | success >> {
“changed”: false,
“ping”: “pong”
}

 

3. Even before starting with the installation, one option is to run the check command to see if there are any issues. Hit the below issue and google showed that it is because of config file.

 


$ ansible-playbook vmwtools.yml -i hosts –check -k
SSH password:

PLAY [ubuntu_vms] *************************************************************

GATHERING FACTS *************************************************************
fatal: [192.168.0.9] => Missing become password

TASK: [Install vmware tools] **************************************************
FATAL: no hosts matched or all hosts have already failed — aborting
$


Change the file and made it “true”

$ cat /etc/ansible/ansible.cfg | grep -i ask_sudo_pass
ask_sudo_pass = True
$


At the end it worked like ease.


(note: some of the output has been removed as it was too long, this is because I used verbose option)

$ ansible-playbook vmwtools.yml -i hosts -k -vvv
SSH password:
SUDO password[defaults to SSH password]:

PLAY [ubuntu_vms] *************************************************************

GATHERING FACTS *************************************************************
<192.168.0.9> ESTABLISH CONNECTION FOR USER: rsa
<192.168.0.9> REMOTE_MODULE setup
<192.168.0.9> EXEC sshpass -d4 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=”/home/rsa/.ansible/cp/ansible-ssh-%h-%p-%r” -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o C

TASK: [Install vmware tools] **************************************************
<192.168.0.9> ESTABLISH CONNECTION FOR USER: rsa
<192.168.0.9> REMOTE_MODULE apt name=open-vm-tools-desktop state=latest update_cache=yes
<192.168.0.9> EXEC sshpass -d7 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o 0ubuntu6) …n”}

PLAY RECAP ************************************************************
192.168.0.9 : ok=2 changed=1 unreachable=0 failed=0


Ansible is idempotent so it does change or do anything if run it again. Changed = 0 after rerunning the command.


me/rsa/.ansible/tmp/ansible-tmp-1438435178.73-12162422762569/ >/dev/null 2>&1′”‘””
ok: [192.168.0.9] => {“changed”: false}

PLAY RECAP ***********************************************************
192.168.0.9 : ok=2 changed=0 unreachable=0 failed=0

$


 

For reference the code is uploaded to my git repo:

https://github.com/rajeevrn/myscripts/tree/master/ansible/vmwaretools

Download the scripts, change the host details and get going.

vmtools_running

 

Leave a Reply

Your email address will not be published. Required fields are marked *