mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Formatting changes as suggested by pre-commit
This commit is contained in:
parent
3deaae2697
commit
8c06378dd8
1 changed files with 23 additions and 28 deletions
|
@ -101,17 +101,16 @@ def __virtual__():
|
|||
|
||||
proc = subprocess.run(
|
||||
[ansible_doc_bin, "--list", "--json", "--type=module"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
shell=False,
|
||||
universal_newlines=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
return (
|
||||
False,
|
||||
"Failed to get the listing of ansible modules:\n{}".format(proc.stderr),
|
||||
f"Failed to get the listing of ansible modules:\n{proc.stderr}",
|
||||
)
|
||||
|
||||
module_funcs = dir(sys.modules[__name__])
|
||||
|
@ -170,11 +169,10 @@ def help(module=None, *args):
|
|||
|
||||
proc = subprocess.run(
|
||||
[ansible_doc_bin, "--json", "--type=module", module],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
shell=False,
|
||||
universal_newlines=True,
|
||||
text=True,
|
||||
env=env,
|
||||
)
|
||||
data = salt.utils.json.loads(proc.stdout)
|
||||
|
@ -240,7 +238,7 @@ def call(module, *args, **kwargs):
|
|||
_kwargs = {k: v for (k, v) in kwargs.items() if not k.startswith("__pub")}
|
||||
|
||||
for key, value in _kwargs.items():
|
||||
module_args.append("{}={}".format(key, salt.utils.json.dumps(value)))
|
||||
module_args.append(f"{key}={salt.utils.json.dumps(value)}")
|
||||
|
||||
with NamedTemporaryFile(mode="w") as inventory:
|
||||
|
||||
|
@ -263,10 +261,9 @@ def call(module, *args, **kwargs):
|
|||
"-i",
|
||||
inventory.name,
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
capture_output=True,
|
||||
timeout=__opts__.get("ansible_timeout", DEFAULT_TIMEOUT),
|
||||
universal_newlines=True,
|
||||
text=True,
|
||||
check=True,
|
||||
shell=False,
|
||||
env=env,
|
||||
|
@ -367,15 +364,15 @@ def playbooks(
|
|||
if diff:
|
||||
command.append("--diff")
|
||||
if isinstance(extra_vars, dict):
|
||||
command.append("--extra-vars='{}'".format(json.dumps(extra_vars)))
|
||||
command.append(f"--extra-vars='{json.dumps(extra_vars)}'")
|
||||
elif isinstance(extra_vars, str) and extra_vars.startswith("@"):
|
||||
command.append("--extra-vars={}".format(extra_vars))
|
||||
command.append(f"--extra-vars={extra_vars}")
|
||||
if flush_cache:
|
||||
command.append("--flush-cache")
|
||||
if inventory:
|
||||
command.append("--inventory={}".format(inventory))
|
||||
command.append(f"--inventory={inventory}")
|
||||
if limit:
|
||||
command.append("--limit={}".format(limit))
|
||||
command.append(f"--limit={limit}")
|
||||
if list_hosts:
|
||||
command.append("--list-hosts")
|
||||
if list_tags:
|
||||
|
@ -383,25 +380,25 @@ def playbooks(
|
|||
if list_tasks:
|
||||
command.append("--list-tasks")
|
||||
if module_path:
|
||||
command.append("--module-path={}".format(module_path))
|
||||
command.append(f"--module-path={module_path}")
|
||||
if skip_tags:
|
||||
command.append("--skip-tags={}".format(skip_tags))
|
||||
command.append(f"--skip-tags={skip_tags}")
|
||||
if start_at_task:
|
||||
command.append("--start-at-task={}".format(start_at_task))
|
||||
command.append(f"--start-at-task={start_at_task}")
|
||||
if syntax_check:
|
||||
command.append("--syntax-check")
|
||||
if tags:
|
||||
command.append("--tags={}".format(tags))
|
||||
command.append(f"--tags={tags}")
|
||||
if playbook_kwargs:
|
||||
for key, value in playbook_kwargs.items():
|
||||
key = key.replace("_", "-")
|
||||
if value is True:
|
||||
command.append("--{}".format(key))
|
||||
command.append(f"--{key}")
|
||||
elif isinstance(value, str):
|
||||
command.append("--{}={}".format(key, value))
|
||||
command.append(f"--{key}={value}")
|
||||
elif isinstance(value, dict):
|
||||
command.append("--{}={}".format(key, json.dumps(value)))
|
||||
command.append("--forks={}".format(forks))
|
||||
command.append(f"--{key}={json.dumps(value)}")
|
||||
command.append(f"--forks={forks}")
|
||||
cmd_kwargs = {
|
||||
"env": {
|
||||
"ANSIBLE_STDOUT_CALLBACK": "json",
|
||||
|
@ -540,12 +537,10 @@ def discover_playbooks(
|
|||
if path:
|
||||
if not os.path.isabs(path):
|
||||
raise CommandExecutionError(
|
||||
"The given path is not an absolute path: {}".format(path)
|
||||
f"The given path is not an absolute path: {path}"
|
||||
)
|
||||
if not os.path.isdir(path):
|
||||
raise CommandExecutionError(
|
||||
"The given path is not a directory: {}".format(path)
|
||||
)
|
||||
raise CommandExecutionError(f"The given path is not a directory: {path}")
|
||||
return {
|
||||
path: _explore_path(path, playbook_extension, hosts_filename, syntax_check)
|
||||
}
|
||||
|
@ -597,7 +592,7 @@ def _explore_path(path, playbook_extension, hosts_filename, syntax_check):
|
|||
)
|
||||
except Exception as exc:
|
||||
raise CommandExecutionError(
|
||||
"There was an exception while discovering playbooks: {}".format(exc)
|
||||
f"There was an exception while discovering playbooks: {exc}"
|
||||
)
|
||||
|
||||
# Run syntax check validation
|
||||
|
|
Loading…
Add table
Reference in a new issue