From dac4b610c8a0dd67fad408649d855b8384017ddd Mon Sep 17 00:00:00 2001 From: Kate Case Date: Tue, 7 Feb 2023 13:11:59 -0500 Subject: [command] run at least once when retries is 0 (#292) * [command] run at least once when retries is 0 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- plugins/modules/vyos_command.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'plugins') diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index 94f16f3..2ed920c 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -74,7 +74,8 @@ options: - Specifies the number of retries a command should be tried before it is considered failed. The command is run on the target device every retry and evaluated against the I(wait_for) conditionals. - default: 10 + - The commands are run once when I(retries) is set to C(0). + default: 9 type: int interval: description: @@ -175,7 +176,7 @@ def main(): commands=dict(type="list", required=True, elements="raw"), wait_for=dict(type="list", aliases=["waitfor"], elements="str"), match=dict(default="all", choices=["all", "any"]), - retries=dict(default=10, type="int"), + retries=dict(default=9, type="int"), interval=dict(default=1, type="int"), ) @@ -186,6 +187,7 @@ def main(): commands = parse_commands(module, warnings) wait_for = module.params["wait_for"] or list() + conditionals = [] try: conditionals = [Conditional(c) for c in wait_for] except AttributeError as exc: @@ -195,7 +197,8 @@ def main(): interval = module.params["interval"] match = module.params["match"] - for item in range(retries): + # Always run at least once, and then `retries` more times. + for item in range(retries + 1): responses = run_commands(module, commands) for item in list(conditionals): -- cgit v1.2.3