Skip to content

Commit 6e3fa33

Browse files
cli: add option --same-sudo-password
To tell all hosts in the inventory uses the same password, which will be prompted only once.
1 parent a43146a commit 6e3fa33

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/pyinfra_cli/cli.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import warnings
44
from fnmatch import fnmatch
5+
from getpass import getpass
56
from os import chdir as os_chdir, getcwd, path
67
from typing import Iterable, List, Tuple, Union
78

@@ -82,6 +83,12 @@ def _print_support(ctx, param, value):
8283
envvar="PYINFRA_YES",
8384
show_envvar=True,
8485
)
86+
@click.option(
87+
"--same-sudo-password",
88+
is_flag=True,
89+
default=False,
90+
help="All hosts have the same sudo password, so ask only once.",
91+
)
8592
@click.option(
8693
"--limit",
8794
help="Restrict the target hosts by name and group name.",
@@ -274,6 +281,7 @@ def _main(
274281
ssh_key,
275282
ssh_key_password: str,
276283
ssh_password: str,
284+
same_sudo_password: bool,
277285
shell_executable,
278286
sudo: bool,
279287
sudo_user: str,
@@ -344,6 +352,9 @@ def _main(
344352
ssh_password,
345353
)
346354

355+
if same_sudo_password:
356+
config.SUDO_PASSWORD = getpass("sudo password: ")
357+
347358
if yes is False:
348359
_set_fail_prompts(state, config)
349360

tests/test_cli/test_cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ def test_deploy_operation_direct(self):
170170
ssh_key=None,
171171
ssh_key_password=None,
172172
ssh_password=None,
173+
same_sudo_password=False,
173174
sudo=False,
174175
sudo_user=None,
175176
use_sudo_password=False,

0 commit comments

Comments
 (0)