Install roles via Ansible Galaxy 32/9432/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 14 Mar 2018 03:10:00 +0000 (23:10 -0400)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 15 Mar 2018 14:54:29 +0000 (10:54 -0400)
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 <thanh.ha@linuxfoundation.org>
.gitignore
README.markdown
ansible-galaxy.sh [new file with mode: 0755]
provision/baseline.yaml
provision/docker.yaml
requirements.yaml [new file with mode: 0644]
templates/docker.json

index 60d1f4e..c63ecaf 100644 (file)
@@ -1,3 +1,4 @@
+.galaxy/
 .tox/
 cloud-env.json
 *.retry
index d66d008..ae710b9 100644 (file)
@@ -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 (executable)
index 0000000..bccd666
--- /dev/null
@@ -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
index aee1b82..1d4f70e 100644 (file)
@@ -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}}'
       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
index 6afb332..39a7206 100644 (file)
@@ -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 (file)
index 0000000..7bafece
--- /dev/null
@@ -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
index 94f11ef..01fe021 100644 (file)
@@ -1,5 +1,6 @@
 {
   "variables": {
+    "ansible_roles_path": ".galaxy",
     "base_image": null,
     "distro": null,
     "cloud_auth_url": null,
       ],
       "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"
       ]