From 99f875674576f3643c9713750a7017f581ff758b Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Mon, 8 Jan 2018 18:37:10 -0500 Subject: [PATCH] Bootstrap Ansible if not available Check if Ansible is already installed on the system and install it if necessary. Change-Id: I8d89cf656642a333b3ba6214d12af9d7187acd59 Signed-off-by: Thanh Ha --- provision/install-ansible.sh | 24 ++++++++++++++++++++++++ templates/builder.json.example | 1 + templates/docker.json.example | 1 + 3 files changed, 26 insertions(+) create mode 100644 provision/install-ansible.sh diff --git a/provision/install-ansible.sh b/provision/install-ansible.sh new file mode 100644 index 0000000..12541c7 --- /dev/null +++ b/provision/install-ansible.sh @@ -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 diff --git a/templates/builder.json.example b/templates/builder.json.example index 5f709ef..f7687b4 100644 --- a/templates/builder.json.example +++ b/templates/builder.json.example @@ -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" diff --git a/templates/docker.json.example b/templates/docker.json.example index 6e92844..be38e8c 100644 --- a/templates/docker.json.example +++ b/templates/docker.json.example @@ -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" -- 2.16.6