diff --git a/source/modules/misc/arguments.py b/source/modules/misc/arguments.py index e45644b1..0ad42a7f 100644 --- a/source/modules/misc/arguments.py +++ b/source/modules/misc/arguments.py @@ -59,6 +59,8 @@ def create_parser() -> ArgumentParser: parser.add_argument("--runner-stdout", nargs=1, default=[None], metavar='STDOUT_PLUGIN', help= 'Provide name of runner stdout callback plugin you would like to use.') + parser.add_argument("--runner-verbosity", nargs=1, default=[1], metavar='N', + help='Set runner verbosity to N*v.') parser.add_argument("--self-setup", nargs=1, default=[None], metavar="LOCAL_SETUP_PATH", help='Setup repo outside of workdir in requested path. This option' ' applies only to infrastructures with allow_user_checkout enabled' @@ -138,6 +140,8 @@ def validate_rest_arguments(self, arguments: Namespace, print_end: str, print_fa options["runner_raw_file"] = arguments.runner_raw_file options["runner_stdout"] = self.validate_ansible_stdout_callback(arguments.runner_stdout, print_fail, print_end) + options["runner_verb"] = self.validate_integer(arguments.runner_verbosity[0], print_fail, + print_end) options["self_setup"] = os.path.abspath(arguments.self_setup[0]) if arguments.self_setup[0]\ else None options["stage"] = arguments.stage[0] @@ -180,3 +184,12 @@ def validate_ansible_callback(stdout_plugin: str, print_fail: str, print_end: st sys.exit(57) else: return [] + + @staticmethod + def validate_integer(number: str, print_fail: str, print_end: str) -> Optional[int]: + """Validate if number is an integer""" + try: + return int(number) + except ValueError: + print(f"{print_fail}[CRITICAL]: Not an integer!{print_end}") + sys.exit(57) diff --git a/source/modules/runners/run.py b/source/modules/runners/run.py index 52ae9340..76614f3e 100644 --- a/source/modules/runners/run.py +++ b/source/modules/runners/run.py @@ -213,7 +213,7 @@ def construct_command(self, playitem: str, inventory: str, config: dict, options command.append("--junit-xml=junit_"+options['task']+'.xml') command.append("./"+playitem["file"]) else: - command = ["ansible-playbook", "-v", "-i", inventory, playitem["file"]] + command = ["ansible-playbook", "-i", inventory, playitem["file"]] if options["limit"]: command.append("-l") command.append(options["limit"]) @@ -226,6 +226,9 @@ def construct_command(self, playitem: str, inventory: str, config: dict, options if options["check_mode"]: command.append("-C") + if options["runner_verb"]: + command.append(f'-{"v"*options["runner_verb"]}') + return command def construct_env(self, options: dict, callback_settings: dict) -> dict: diff --git a/tests/02a-checkrun.sh b/tests/02a-checkrun.sh index 797345c3..8f5d2181 100755 --- a/tests/02a-checkrun.sh +++ b/tests/02a-checkrun.sh @@ -80,8 +80,8 @@ check_run_ok "ansible-deployer run --task task_with_limit --stage testing --infr check_run_ok "ansible-deployer run --task task_without_limit --stage testing --infrastructure testInfra --limit testHost1 --check-mode" # Check if deployer exits on 1st play item fail -check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to" -check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully" +check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to" +check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully" # Check --keep-locked option check_message_in_output "ansible-deployer run --task task_exec_bin_true --stage testing --infrastructure testInfra --keep-locked --debug" "\[DEBUG\]: Keep locked infra testInfra:testing ." diff --git a/tests/02a-checkrun_short.sh b/tests/02a-checkrun_short.sh index e3fa99bd..aabf33f3 100755 --- a/tests/02a-checkrun_short.sh +++ b/tests/02a-checkrun_short.sh @@ -77,8 +77,8 @@ check_run_ok "ansible-deployer run -t task_with_limit -s testing -i testInfra2 - check_run_ok "ansible-deployer run -t task_without_limit -s testing -i testInfra -l testHost1 -C" # Check if deployer exits on 1st play item fail -check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to" -check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully" +check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to" +check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully" # Check --keep-locked option check_message_in_output "ansible-deployer run -t task_exec_bin_true -s testing -i testInfra -k -d" "\[DEBUG\]: Keep locked infra testInfra:testing ." diff --git a/tests/02b-checkrun_with_conf_dir.sh b/tests/02b-checkrun_with_conf_dir.sh index 059f11d2..e152232d 100755 --- a/tests/02b-checkrun_with_conf_dir.sh +++ b/tests/02b-checkrun_with_conf_dir.sh @@ -62,8 +62,8 @@ check_run_ok "ansible-deployer run --task task_with_limit --stage testing --infr check_run_ok "ansible-deployer run --task task_without_limit --stage testing --infrastructure testInfra --limit testHost1 --check-mode --conf-dir=/etc/alternate-deployer-dir" # Check if deployer exits on 1st play item fail -check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to" -check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully" +check_message_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to" +check_message_not_in_output "ansible-deployer run --task task_with_ansible_fail --stage testing --infrastructure testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully" echo -e " ___ ____ _ _ _ _ _ _ __ _ _\n / _ \___ \| |__ ___| |__ ___ ___| | ___ __ _ _ _ __ __ _(_) |_| |__ ___ ___ _ __ / _| __| (_)_ __\n | | | |__) | '_ \ _____ / __| '_ \ / _ \/ __| |/ / '__| | | | '_ \ \ \ /\ / / | __| '_ \ / __/ _ \| '_ \| |_ / _\` | | '__|\n | |_| / __/| |_) | |_____| | (__| | | | __/ (__| <| | | |_| | | | | \ V V /| | |_| | | | | (_| (_) | | | | _| | (_| | | |\n \___/_____|_.__/ \___|_| |_|\___|\___|_|\_\_| \__,_|_| |_| \_/\_/ |_|\__|_| |_| \___\___/|_| |_|_| \__,_|_|_|\n \n _ _\n _ __ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___\n | '_ \ / _ \ '__| '_ \` _ \| / __/ __| |/ _ \| '_ \/ __|\n | |_) | __/ | | | | | | | \__ \__ \ | (_) | | | \__ \ \n | .__/ \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/\n |_|\n" # Try execution of task without permissions diff --git a/tests/02b-checkrun_with_conf_dir_short.sh b/tests/02b-checkrun_with_conf_dir_short.sh index 21f6cf5d..2909e9f9 100755 --- a/tests/02b-checkrun_with_conf_dir_short.sh +++ b/tests/02b-checkrun_with_conf_dir_short.sh @@ -62,8 +62,8 @@ check_run_ok "ansible-deployer run -t task_with_limit -s testing -i testInfra2 - check_run_ok "ansible-deployer run -t task_without_limit -s testing -i testInfra -l testHost1 -C --conf-dir=/etc/alternate-deployer-dir" # Check if deployer exits on 1st play item fail -check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runll.yaml\" failed due to" -check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -v -i ./test_infra1_inv.yaml runBinTrue.yaml\" ran succesfully" +check_message_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[ERROR\]: \"ansible-playbook -i ./test_infra1_inv.yaml runll.yaml -v\" failed due to" +check_message_not_in_output "ansible-deployer run -t task_with_ansible_fail -s testing -i testInfra --conf-dir=/etc/alternate-deployer-dir" "\[INFO\]: \"ansible-playbook -i ./test_infra1_inv.yaml runBinTrue.yaml -v\" ran succesfully" echo -e " ___ ____ _ _ _ _ _ _ __ _ _ _ _\n / _ \___ \| |__ ___| |__ ___ ___| | ___ __ _ _ _ __ __ _(_) |_| |__ ___ ___ _ __ / _| __| (_)_ __ ___| |__ ___ _ __| |_\n | | | |__) | '_ \ _____ / __| '_ \ / _ \/ __| |/ / '__| | | | '_ \ \ \ /\ / / | __| '_ \ / __/ _ \| '_ \| |_ / _\` | | '__| / __| '_ \ / _ \| '__| __|\n | |_| / __/| |_) | |_____| | (__| | | | __/ (__| <| | | |_| | | | | \ V V /| | |_| | | | | (_| (_) | | | | _| | (_| | | | \__ \ | | | (_) | | | |_\n \___/_____|_.__/ \___|_| |_|\___|\___|_|\_\_| \__,_|_| |_| \_/\_/ |_|\__|_| |_| \___\___/|_| |_|_| \__,_|_|_| |___/_| |_|\___/|_| \__|\n \n _ _\n _ __ ___ _ __ _ __ ___ (_)___ ___(_) ___ _ __ ___\n | '_ \ / _ \ '__| '_ \` _ \| / __/ __| |/ _ \| '_ \/ __|\n | |_) | __/ | | | | | | | \__ \__ \ | (_) | | | \__ \ \n | .__/ \___|_| |_| |_| |_|_|___/___/_|\___/|_| |_|___/\n |_|\n" # Try execution of task without permissions