From 8eb7afa95a1560e487c6aba351b240e0695a68fb Mon Sep 17 00:00:00 2001
From: Jesse Pretorius <jesse.pretorius@rackspace.co.uk>
Date: Thu, 30 Aug 2018 21:15:21 +0100
Subject: [PATCH] MNAIO: Apply workaround for bug in libguestfs appliance

Without the dash package in the supermin appliance, guestfish
is unable to write into the images. Ubuntu has not updated their
package to a recent enough version, so we apply the workaround.

Change-Id: If48045c9b6e0cffe3d6a188e8a09a1e58ee885a8
---
 multi-node-aio/playbooks/setup-host.yml | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/multi-node-aio/playbooks/setup-host.yml b/multi-node-aio/playbooks/setup-host.yml
index b5c7309d..8791d4c9 100644
--- a/multi-node-aio/playbooks/setup-host.yml
+++ b/multi-node-aio/playbooks/setup-host.yml
@@ -81,6 +81,24 @@
       retries: 3
       delay: 15
 
+    - name: Get version of libguestfs
+      shell: >-
+        guestfish --version | awk '{print $2}'
+      changed_when: false
+      register: _libguestfs_version
+
+    # See:
+    # https://bugzilla.redhat.com/show_bug.cgi?id=1591617
+    # https://bugs.launchpad.net/ubuntu/+source/libguestfs/+bug/1615337
+    - name: Apply workaround for older versions to make guestfish work
+      shell: >-
+        echo dash > /usr/lib/x86_64-linux-gnu/guestfs/supermin.d/zz-dash-packages
+        rm -rf /var/tmp/.guestfs
+      when:
+        - "{{ (_libguestfs_version.stdout is version('1.38.1', '<')) or
+              ((_libguestfs_version.stdout is version('1.39.0', '>=')) and
+               (_libguestfs_version.stdout is version('1.39.1', '<'))) }}"
+
     - name: Ensure root has a .ssh directory
       file:
         path: /root/.ssh