diff mbox series

[3/3] ansible.Makefile: enhance ansible verbosity

Message ID 20250203-fix-dbg-v1-3-3575fb40f2bc@samsung.com (mailing list archive)
State New
Headers show
Series Fix debug mode | expand

Commit Message

Daniel Gomez Feb. 3, 2025, 12:35 p.m. UTC
Ansible verbosity is controlled via V=2 parameter/value. This however
has a limited configuration as it hardcodes the output of the -v,
--verbose command of ansible-playbook to level 3 (-vvv). Drop support
for V=2 mode in favor of AV=<number> where <number> indicates the level
of verbosity from 0 (empty string) to max 6 (-vvvvvv).

Add a helper script in python to handle the new AV parameter. This makes
it easier to check for corner cases.

Also, restore verbosity help from commit 6539f3f ("Merge commit
'6539f3f6b5cf1393cb63f9ad9aac51877f088734'") and adapt V=2 to the new
AV= parameter.

Add a maintainer entry for this new Ansible wrapper. A reason to add
a specific entry here is to extend the new ansible.Makefile with all
Ansible calls across kdevops and make it easier to maintain in the long
term.

Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 MAINTAINERS              |  8 ++++++++
 Makefile                 |  6 ++----
 scripts/ansible.Makefile |  4 ++++
 scripts/kconfig/Makefile |  4 ++++
 scripts/validate_av.py   | 28 ++++++++++++++++++++++++++++
 5 files changed, 46 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index b2b81a9e5b18a46fe1b34d5137a817cce5526d34..045d8c96208ef8f3f1c5d74d023a5117529511cf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -67,6 +67,14 @@  Maintainers List
           first. When adding to this list, please keep the entries in
           alphabetical order.
 
+ANSIBLE WRAPPER
+M:	Daniel Gomez <da.gomez@samsung.com>
+L:	kdevops@lists.linux.dev
+S:	Maintained
+T:	git https://github.com/linux-kdevops/kdevops.git
+F:	scripts/ansible_av.py
+F:	scripts/ansible.Makefile
+
 GITREF
 M:	Daniel Gomez <da.gomez@samsung.com>
 L:	kdevops@lists.linux.dev
diff --git a/Makefile b/Makefile
index 56a6905fa11795625ab1912ceb54a6847ecad656..14e647dcd45190ff51dd42627f58826998f07781 100644
--- a/Makefile
+++ b/Makefile
@@ -46,10 +46,6 @@  export Q=@
 export NQ=echo
 endif
 
-ifneq ($(findstring 2, $(V)),)
-  export ANSIBLE_VERBOSE := '-vvv'
-endif
-
 include Makefile.min_deps
 DEFAULT_DEPS += $(KDEVOPS_DEPCHECK)
 
@@ -62,6 +58,8 @@  ANSIBLE_EXTRA_ARGS_SEPARATED :=
 ANSIBLE_EXTRA_ARGS_DIRECT :=
 include Makefile.extra_vars
 
+include scripts/ansible.Makefile
+
 LIMIT_HOSTS :=
 ifneq (,$(HOSTS))
 LIMIT_HOSTS := '-l $(subst ${space},$(comma),$(HOSTS))'
diff --git a/scripts/ansible.Makefile b/scripts/ansible.Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..b0d2a8c12ee74a13e0b95e349565a8c55d538b79
--- /dev/null
+++ b/scripts/ansible.Makefile
@@ -0,0 +1,4 @@ 
+# SPDX-License-Identifier: copyleft-next-0.3.1
+
+AV ?= 0
+export ANSIBLE_VERBOSE := $(shell scripts/validate_av.py --av "$(AV)")
diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile
index e3694365bf98281a00fb56d76d3400d236776476..76e4f5c36a4bb11653e93fdc874d4ba73db7a848 100644
--- a/scripts/kconfig/Makefile
+++ b/scripts/kconfig/Makefile
@@ -70,6 +70,10 @@  help:
 	@echo "allnoconfig        - disables all bells and whistles"
 	@echo "randconfig         - random configuration"
 	@echo "defconfig-*        - If you have files in the defconfig directory use default config from there"
+	@echo
+	@echo "Variable options:"
+	@echo "make V=n [targets] 1:      verbose build (Makefile)"
+	@echo "make AV=n [targets] 0-6:   verbose build (Ansible)"
 
 .PHONY: clean
 clean:
diff --git a/scripts/validate_av.py b/scripts/validate_av.py
new file mode 100755
index 0000000000000000000000000000000000000000..fffb836f593bc284adc3c9104deea0aea97814aa
--- /dev/null
+++ b/scripts/validate_av.py
@@ -0,0 +1,28 @@ 
+#!/usr/bin/env python3
+# SPDX-License-Identifier: copyleft-next-0.3.1
+
+import argparse
+
+
+def get_ansible_verbosity(av: str, max_level: int = 6) -> str:
+    """Return Ansible verbosity flag (e.g. -vv or emtpy)."""
+    try:
+        av = int(av)
+    except ValueError:
+        return ""
+    av = max(0, min(av, max_level))
+    return "-" + "v" * av if av > 0 else ""
+
+
+def main():
+    parser = argparse.ArgumentParser(
+        description="Validate and return Ansible verbosity level."
+    )
+    parser.add_argument("--av", type=str, default="0", help="Verbosity level (0-6)")
+
+    args = parser.parse_args()
+    print(get_ansible_verbosity(args.av))
+
+
+if __name__ == "__main__":
+    main()