From 8287be9012178ea619ebfd35aafa1a1f9d219055 Mon Sep 17 00:00:00 2001 From: William Yeh Date: Mon, 29 Jun 2015 08:05:38 +0800 Subject: [PATCH] Add: install Galaxy roles according to requirements.yml. Inspired: PR from goettl79 - https://github.com/William-Yeh/docker-ansible/pull/1 --- README.md | 24 ++++++++++------ centos6-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- centos7-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- debian7-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- debian8-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- ubuntu12.04-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- ubuntu14.04-onbuild/ansible-playbook-wrapper | 29 ++++++++++++++++---- 7 files changed, 159 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index b41d1d2..8fd53bb 100644 --- a/README.md +++ b/README.md @@ -53,11 +53,14 @@ Second, put the following `Dockerfile` along with your playbook directory: ``` FROM williamyeh/ansible:ubuntu14.04-onbuild -# ==> Specify playbook filename; default = "playbook.yml" -#ENV PLAYBOOK playbook.yml +# ==> Specify requirements filename; default = "requirements.yml" +#ENV REQUIREMENTS requirements.yml -# ==> Specify inventory filename; default = "/etc/ansible/hosts" -#ENV INVENTORY inventory.ini +# ==> Specify playbook filename; default = "playbook.yml" +#ENV PLAYBOOK playbook.yml + +# ==> Specify inventory filename; default = "/etc/ansible/hosts" +#ENV INVENTORY inventory.ini # ==> Executing Ansible... RUN ansible-playbook-wrapper @@ -67,7 +70,7 @@ Third, `docker build .` Done! -For more advanced usage, the role in Ansible Galaxy [`williamyeh/nginx`](https://galaxy.ansible.com/list#/roles/2245) also demonstrates how to do a simple integration test for a variety of Linux distributions on [Travis CI](https://travis-ci.org/)’s Ubuntu 12.04 worker instances. +For more advanced usage, the role in Ansible Galaxy [`williamyeh/nginx`](https://galaxy.ansible.com/list#/roles/2245) also demonstrates how to do a simple integration test for a variety of Linux distributions on [CircleCI](https://circleci.com/)'s and [Travis CI](https://travis-ci.org/)’s Ubuntu 12.04 worker instances. @@ -173,11 +176,14 @@ FROM williamyeh/ansible:ubuntu14.04-onbuild #FROM williamyeh/ansible:centos6-onbuild -# ==> Specify playbook filename; default = "playbook.yml" -#ENV PLAYBOOK playbook.yml +# ==> Specify requirements filename; default = "requirements.yml" +#ENV REQUIREMENTS requirements.yml + +# ==> Specify playbook filename; default = "playbook.yml" +#ENV PLAYBOOK playbook.yml -# ==> Specify inventory filename; default = "/etc/ansible/hosts" -#ENV INVENTORY inventory.ini +# ==> Specify inventory filename; default = "/etc/ansible/hosts" +#ENV INVENTORY inventory.ini # ==> Executing Ansible... RUN ansible-playbook-wrapper diff --git a/centos6-onbuild/ansible-playbook-wrapper b/centos6-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/centos6-onbuild/ansible-playbook-wrapper +++ b/centos6-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi diff --git a/centos7-onbuild/ansible-playbook-wrapper b/centos7-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/centos7-onbuild/ansible-playbook-wrapper +++ b/centos7-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi diff --git a/debian7-onbuild/ansible-playbook-wrapper b/debian7-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/debian7-onbuild/ansible-playbook-wrapper +++ b/debian7-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi diff --git a/debian8-onbuild/ansible-playbook-wrapper b/debian8-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/debian8-onbuild/ansible-playbook-wrapper +++ b/debian8-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi diff --git a/ubuntu12.04-onbuild/ansible-playbook-wrapper b/ubuntu12.04-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/ubuntu12.04-onbuild/ansible-playbook-wrapper +++ b/ubuntu12.04-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi diff --git a/ubuntu14.04-onbuild/ansible-playbook-wrapper b/ubuntu14.04-onbuild/ansible-playbook-wrapper index bf137c8..0ba45e6 100755 --- a/ubuntu14.04-onbuild/ansible-playbook-wrapper +++ b/ubuntu14.04-onbuild/ansible-playbook-wrapper @@ -1,17 +1,36 @@ #!/bin/sh # -# Simple wrapper for executing ansible-playbook with local connection. +# Simple wrapper for executing ansible-galaxy and ansible-playbook +# with local connection. # # USAGE: # ansible-playbook-wrapper [other ansible-playbook arguments] # # ENVIRONMENT VARIABLES: -# -# - PLAYBOOK: playbook filename; default = "playbook.yml" -# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" -# +# +# - REQUIREMENTS: requirements filename; default = "requirements.yml" +# - PLAYBOOK: playbook filename; default = "playbook.yml" +# - INVENTORY: inventory filename; default = "/etc/ansible/hosts" +# +# +# install Galaxy roles, if any +# + +if [ -z "$REQUIREMENTS" ]; then + REQUIREMENTS=requirements.yml +fi + +if [ -f "$REQUIREMENTS" ]; then + ansible-galaxy install -r $REQUIREMENTS +fi + + +# +# execute playbook +# + if [ -z "$PLAYBOOK" ]; then PLAYBOOK=playbook.yml fi -- 2.41.0