From: Thanh Ha Date: Wed, 14 Mar 2018 03:10:00 +0000 (-0400) Subject: Install roles via Ansible Galaxy X-Git-Tag: v0.1.0~43 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=e3344fc74b1fc3e40cf8f4f7e713047373d9b177;p=releng%2Fcommon-packer.git Install roles via Ansible Galaxy Support using Ansible Galaxy to install lf-ansible roles. This patch adds a new script ansible-galaxy.sh which will install roles from common-packer's requirements.yaml and if provided local project requirements.yaml as well. The project local requirements.yaml needs to exist in their local packer directory. Change-Id: I06bb5d433bac37b3c08e761c25dfdf942b4f3229 Signed-off-by: Thanh Ha --- diff --git a/.gitignore b/.gitignore index 60d1f4e..c63ecaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.galaxy/ .tox/ cloud-env.json *.retry diff --git a/README.markdown b/README.markdown index d66d008..ae710b9 100644 --- a/README.markdown +++ b/README.markdown @@ -93,6 +93,14 @@ to the docker template and provisioning script for an example of how it imports the existing baseline playbook into the local playbook to reduce duplication in code. +## Installing Roles from Ansible Galaxy + +Common-packer contains a script `ansible-galaxy.sh` which runs +`ansible-galaxy install -r requirements.yaml` from the common-packer repo to +install common-packer role dependencies. In the local +ci-management/packer directory a project can provide it's own requirements.yaml +to pull in roles before running a Packer build. + ## Local testing of common-packer For developers of common-packer who would like to be able to locally test from diff --git a/ansible-galaxy.sh b/ansible-galaxy.sh new file mode 100755 index 0000000..bccd666 --- /dev/null +++ b/ansible-galaxy.sh @@ -0,0 +1,20 @@ +#!/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 +############################################################################## + +ANSIBLE_ROLES_PATH="${1:-.galaxy}" +ANSIBLE_REQUIREMENTS_FILE="${2:-requirements.yaml}" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +ansible-galaxy install -p "$ANSIBLE_ROLES_PATH" -r "$SCRIPT_DIR/requirements.yaml" + +if [ -f "$ANSIBLE_REQUIREMENTS_FILE" ]; then + ansible-galaxy install -p "$ANSIBLE_ROLES_PATH" -r "requirements.yaml" +fi diff --git a/provision/baseline.yaml b/provision/baseline.yaml index aee1b82..1d4f70e 100644 --- a/provision/baseline.yaml +++ b/provision/baseline.yaml @@ -4,7 +4,7 @@ become_method: sudo pre_tasks: - - include_role: name=system-update + - include_role: name=lfit.system-update - name: Install base packages include_tasks: '{{item}}' @@ -22,14 +22,14 @@ become: yes roles: - - lf-recommended-tools - - lf-dev-libs - - haveged-install - - java-install - - puppet-install - - python-install - - shellcheck-install - - sysstat-install + - lfit.lf-recommended-tools + - lfit.lf-dev-libs + - lfit.haveged-install + - lfit.java-install + - lfit.puppet-install + - lfit.python-install + - lfit.shellcheck-install + - lfit.sysstat-install post_tasks: - name: Update /etc/nss-switch.conf to map hostname with IP diff --git a/provision/docker.yaml b/provision/docker.yaml index 6afb332..39a7206 100644 --- a/provision/docker.yaml +++ b/provision/docker.yaml @@ -6,10 +6,10 @@ become_method: sudo pre_tasks: - - include_role: name=system-update + - include_role: name=lfit.system-update roles: - - { role: docker-install, mtu: 1458 } + - { role: lfit.docker-install, mtu: 1458 } post_tasks: - name: System Reseal diff --git a/requirements.yaml b/requirements.yaml new file mode 100644 index 0000000..7bafece --- /dev/null +++ b/requirements.yaml @@ -0,0 +1,14 @@ +--- +- src: lfit.docker-install +- src: lfit.haveged-install +- src: lfit.java-install +- src: lfit.lf-dev-libs +- src: lfit.lf-recommended-tools +- src: lfit.mono-install +- src: lfit.packer-install +- src: lfit.protobuf-install +- src: lfit.puppet-install +- src: lfit.python-install +- src: lfit.shellcheck-install +- src: lfit.sysstat-install +- src: lfit.system-update diff --git a/templates/docker.json b/templates/docker.json index 94f11ef..01fe021 100644 --- a/templates/docker.json +++ b/templates/docker.json @@ -1,5 +1,6 @@ { "variables": { + "ansible_roles_path": ".galaxy", "base_image": null, "distro": null, "cloud_auth_url": null, @@ -44,13 +45,17 @@ ], "execute_command": "chmod +x {{ .Path }}; if [ \"$UID\" == \"0\" ]; then {{ .Vars }} '{{ .Path }}'; else {{ .Vars }} sudo -E '{{ .Path }}'; fi" }, + { + "type": "shell-local", + "command": "./common-packer/ansible-galaxy.sh {{user `ansible_roles_path`}}" + }, { "type": "ansible", "playbook_file": "provision/local-docker.yaml", "ansible_env_vars": [ "ANSIBLE_NOCOWS=1", "ANSIBLE_PIPELINING=True", - "ANSIBLE_ROLES_PATH=../lf-ansible/roles", + "ANSIBLE_ROLES_PATH={{user `ansible_roles_path`}}", "ANSIBLE_CALLBACK_WHITELIST=profile_tasks", "ANSIBLE_STDOUT_CALLBACK=debug" ]