[libvirt-jenkins-ci PATCH v2 2/6] guests: Introduce lcitool

[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.

It also takes over ownership of the Ansible vault password, which
is now expected to be stored in lcitool's own config directory
along with more settings that will be introduced later.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 guests/Makefile    | 12 ---------
 guests/ansible.cfg |  1 -
 guests/lcitool     | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+), 13 deletions(-)
 delete mode 100644 guests/Makefile
 create mode 100755 guests/lcitool

diff --git a/guests/Makefile b/guests/Makefile
deleted file mode 100644
index 39ebe52..0000000
--- a/guests/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-all:
-
-site:
-	@ansible-playbook site.yml
-
-bootstrap:
-	@ansible-playbook --ask-pass bootstrap.yml
-
-clean:
-	@rm -f *.retry log
-
-.PHONY: all site bootstrap clean
diff --git a/guests/ansible.cfg b/guests/ansible.cfg
index 84fde77..6b18c57 100644
--- a/guests/ansible.cfg
+++ b/guests/ansible.cfg
@@ -5,7 +5,6 @@ inventory = ./inventory
 log_path = ./log
 nocows = 1
 squash_actions = package
-vault_password_file = ~/.ansible/libvirt-jenkins-ci.vault-password
 
 [ssh_connection]
 pipelining = True
diff --git a/guests/lcitool b/guests/lcitool
new file mode 100755
index 0000000..aaee5f9
--- /dev/null
+++ b/guests/lcitool
@@ -0,0 +1,76 @@
+#!/bin/sh
+
+# -------------------
+#  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: $CALL_NAME ACTION [OPTIONS]
+
+Actions:
+  list                 List known guests
+  prepare GUEST|all    Prepare or update GUEST. Can be run multiple times
+  update  GUEST|all    Alias for prepare
+  help                 Display this help"
+}
+
+do_list() {
+    # List all guests present in the inventory. Skip group names,
+    # comments and empty lines
+    grep -vE '^#|^\[|^$' inventory | sort -u
+}
+
+do_prepare() {
+    GUEST="$1"
+
+    test "$GUEST" || {
+        die "$(do_help)"
+    }
+    do_list | grep -q "$GUEST" || test "$GUEST" = all || {
+        die "$PROGRAM_NAME: $GUEST: Unknown guest"
+    }
+
+    VAULT_PASS_FILE="$CONFIG_DIR/vault-password"
+
+    # Make sure required passwords exist and are not invalid (empty)
+    test -f "$VAULT_PASS_FILE" && test "$(cat "$VAULT_PASS_FILE")" || {
+        die "$PROGRAM_NAME: $VAULT_PASS_FILE: Missing or invalid password"
+    }
+
+    ansible-playbook \
+        --vault-password-file "$VAULT_PASS_FILE" \
+        -l "$GUEST" \
+        site.yml
+}
+
+# ---------------------
+#  Program entry point
+# ---------------------
+
+CALL_NAME="$0"
+PROGRAM_NAME="${0##*/}"
+CONFIG_DIR="$HOME/.config/$PROGRAM_NAME"
+
+test -f "$PROGRAM_NAME" || {
+    die "$PROGRAM_NAME: Must be run from the source directory"
+}
+
+case "$1" in
+    list)           do_list ;;
+    prepare|update) do_prepare "$2" ;;
+    *help)          do_help ;;
+    *)              die "$(do_help)" ;;
+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