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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This script replaces the existing Makefile, and will be extended
to provide more functionality in future commits.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 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}
+
+    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]" ;;
+esac
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux