[libvirt] [libvirt-jenkins-ci PATCH 2/5] ansible: Introduce the 'manage' tool

Pavel Hrdina phrdina at redhat.com
Tue Oct 17 13:21:43 UTC 2017


On Mon, Oct 16, 2017 at 06:02:05PM +0200, Andrea Bolognani wrote:
> This script replaces the existing Makefile, and will be extended
> to provide more functionality in future commits.
> 
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
>  ansible/Makefile |  9 ---------
>  ansible/manage   | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 57 insertions(+), 9 deletions(-)
>  delete mode 100644 ansible/Makefile
>  create mode 100755 ansible/manage
> 
> diff --git a/ansible/Makefile b/ansible/Makefile
> deleted file mode 100644
> index 6af7ae3..0000000
> --- a/ansible/Makefile
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -all:
> -
> -site:
> -	@ansible-playbook site.yml
> -
> -clean:
> -	@rm -f *.retry log
> -
> -.PHONY: all site clean
> diff --git a/ansible/manage b/ansible/manage
> new file mode 100755
> index 0000000..46bec6c
> --- /dev/null
> +++ b/ansible/manage
> @@ -0,0 +1,57 @@
> +#!/bin/sh
> +
> +PROGRAM_NAME="$0"
> +
> +# -------------------
> +#  Utility functions
> +# -------------------
> +
> +# die MESSAGE
> +#
> +# Abort the program after displaying $MESSAGE on standard error.
> +die() {
> +    echo "$1" >&2
> +    exit 1
> +}
> +
> +# ----------------------
> +#  User-visible actions
> +# ----------------------
> +
> +do_help() {
> +    echo "\
> +Usage: $PROGRAM_NAME ACTION [OPTIONS]
> +
> +Actions:
> +  list             List known guests
> +  prepare GUEST    Prepare or update GUEST. Can be run as many times as needed
> +  update GUEST     Alias for prepare
> +  help             Display this help"
> +}
> +
> +do_list() {
> +    INVENTORY=$(grep "^inventory\\s*=" ansible.cfg 2>/dev/null | sed "s/^.*=\\s*//g")
> +    INVENTORY=${INVENTORY:-/etc/ansible/hosts}

I don't think that there is a need to include system-wide inventory
since we have our own inventory and we don't use the system-wide
inventory at all.

> +
> +    grep -v '^\[' "$INVENTORY" | sort -u
> +}
> +
> +do_prepare() {
> +    GUEST="$1"
> +
> +    test "$GUEST" || {
> +        die "Usage: $PROGRAM_NAME prepare GUEST"
> +    }
> +    do_list | grep -q "$GUEST" || {
> +        die "$PROGRAM_NAME: $GUEST: Unknown guest"
> +    }
> +
> +    ansible-playbook -l "$GUEST" site.yml
> +}
> +
> +case "$1" in
> +    list)           do_list ;;
> +    prepare|update) do_prepare "$2" ;;
> +    *help)          do_help ;;
> +    *)              die "Usage: $PROGRAM_NAME ACTION [OPTIONS]" ;;

How about grouping *help) and *) together?  I was pretending to be a
basic user and I've run this script without any option at all and this
was the only output.  So it would be nice to print the help itself
or mention that there is some "--help" option.

> +esac

Pavel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20171017/5dcf348d/attachment-0001.sig>


More information about the libvir-list mailing list