You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
I want to roll out the latest Virtualbox onto my Ubuntu 18.04 servers via ansible.
What I've managed so far is an installer-script that gets copied over to any host in the "virtualbox" hosts group (as per ansible hosts configuration file), then gets remotely executed and does this job.
While this solution "gets the job done" it's more of a "quick and dirty hack" and not really elegant. What's the proper way to do this via pure ansible playbook code? E.g. I would like to write playbook code that determines the latest version of Virtualbox and then installs it, just like the bash script below does. Is there any way to do this?
So my playbook so far looks like this:
```
---
- hosts: virtualbox
tasks:
- name: Copy the repo file if needed
copy:
src: /home/admin/System_Configs/sources.list.d/18.04/virtualbox.list
dest: /etc/apt/sources.list.d/
mode: 0644
owner: root
group: root
- name: Make sure repo keys are installed if needed
apt_key:
url: "https://www.virtualbox.org/download/{{ item }}.asc"
state: present
with_items:
- oracle_vbox
- oracle_vbox_2016
- name: Transfer the installer script
copy:
src: /home/admin/System_Configs/bin/virtualbox-installer.sh
dest: /tmp/
mode: 0755
owner: root
group: root
- name: Execute the installer script
shell: /tmp/virtualbox-installer.sh
changed_when: False
register: scriptoutput
- debug: var={{ item }}
with_items:
- scriptoutput.stdout_lines
```
... and the script that is called looks like this:
```
#! /bin/bash
cd /tmp
rm /tmp/*.vbox-extpack >/dev/null 2>&1
wget -q -N https://download.virtualbox.org/virtualbox/LATEST-STABLE.TXT
VBOXVERSION=`cat /tmp/LATEST-STABLE.TXT`
echo "Latest Virtualbox is: "$VBOXVERSION
MAJORVERSION=`cat /tmp/LATEST-STABLE.TXT | cut -d. -f1,2`
echo "Latest major release is: "$MAJORVERSION
apt install virtualbox-$MAJORVERSION
INSTALLEDVBOXVERSION=`VBoxManage --version | sed -r 's/([0-9])\.([0-9])\.([0-9]{1,2}).*/\1.\2.\3/'`
echo "Installed Virtualbox is: "$INSTALLEDVBOXVERSION
echo
wget -q -N "http://download.virtualbox.org/virtualbox/$INSTALLEDVBOXVERSION/Oracle_VM_VirtualBox_Extension_Pack-$INSTALLEDVBOXVERSION.vbox-extpack"
echo y | VBoxManage extpack install --replace /tmp/Oracle_VM_VirtualBox_Extension_Pack-"$INSTALLEDVBOXVERSION".vbox-extpack | grep Success
rm /tmp/*.vbox-extpack >/dev/null 2>&1
rm /tmp/LATEST-STABLE.TXT >/dev/null 2>&1
```
While the script "gets the job done" ... meh. I'd like a proper ansible playbook that could do this.
All the examples on Ansible Galaxy that I've looked at needed the Virtualbox version number statically defined as variable inside their playbooks or their role's variable definitions.... not really what I want.
I'd like to get ansible to look at the "LATEST-STABLE.TXT" file on Oracle's web site, read that into a variable, and then act accordingly.
So my ansible playbook would need to:
* read the contents of "https://download.virtualbox.org/virtualbox/LATEST-STABLE.TXT"
* assign that resulting number to a variable ("6.0.10")
* cut that number down so we know the major release ("6.0")
* install the "virtualbox-*" package that results from that ("virtualbox-6.0")
* download and install the Extension Package too ("Oracle_VM_VirtualBox_Extension_Pack-6.0.10.vbox-extpack")
I've been tinkering around with "get_url", "slurp", "fetch", "lookup" and what not but I always fail to get the content of "LATEST-STABLE.TXT" assigned to a variable.
What would be a proper Ansible way to do that?
Thanks in advance for any help <3
Knut Karevoll
unread,
Aug 27, 2019, 1:44:40 PM8/27/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ansible Project
What you are looking for is the set_fact module. This allows you to set a variable in the current context which will allow you to use it in the subsequent tasks in the play.