Bootstrap Ansible if not available 98/8298/2
authorThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 8 Jan 2018 23:37:10 +0000 (18:37 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 8 Jan 2018 23:43:10 +0000 (18:43 -0500)
Check if Ansible is already installed on the system and install
it if necessary.

Change-Id: I8d89cf656642a333b3ba6214d12af9d7187acd59
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
provision/install-ansible.sh [new file with mode: 0644]
templates/builder.json.example
templates/docker.json.example

diff --git a/provision/install-ansible.sh b/provision/install-ansible.sh
new file mode 100644 (file)
index 0000000..12541c7
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+# vi: ts=4 sw=4 sts=4 et :
+
+# Packer Ansible provisioner needs Ansible installed so bootstrap if necessary
+if ! command -v /usr/bin/ansible-playbook; then
+    if command -v apt; then
+        apt -y update
+        apt install -y software-properties-common
+        apt-add-repository -y ppa:ansible/ansible
+        apt install -y ansible
+    fi
+    if command -v yum; then
+        yum install -y ansible
+    fi
+fi
index 5f709ef..f7687b4 100644 (file)
@@ -40,6 +40,7 @@
     {
       "type": "shell",
       "scripts": [
+        "common-packer/provision/install-ansible.sh",
         "common-packer/provision/install-python.sh"
       ],
       "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"
index 6e92844..be38e8c 100644 (file)
@@ -40,6 +40,7 @@
     {
       "type": "shell",
       "scripts": [
+        "common-packer/provision/install-ansible.sh",
         "common-packer/provision/install-python.sh"
       ],
       "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi"