From 519c84e7f363e91282a9a1c999895738d034e28a Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 26 Oct 2024 15:48:43 +0200 Subject: [PATCH] feat(playbook): add support for SSH password prompt Introduced a `--ask-pass` argument to prompt for the SSH password, using the same password as the become password when provided. This allows secure SSH connections without pre-stored credentials, enhancing security and flexibility in multi-user environments. --- playbook.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/playbook.py b/playbook.py index b3d8f1b..73dc620 100755 --- a/playbook.py +++ b/playbook.py @@ -17,6 +17,12 @@ def parse_arguments(): default="inventory.yml", help="The path to the inventory file.", ) + parser.add_argument( + "-k", + "--ask-pass", + action="store_true", + help="Use become password as SSH password", + ) return parser.parse_args() @@ -61,7 +67,12 @@ def main(): become_pass = getpass(f"Enter become password for {host}: ") # Use JSON to safely pass the become password as an extra var - extra_vars = json.dumps({"ansible_become_pass": become_pass}) + raw_vars = {"ansible_become_pass": become_pass} + + if args.ask_pass: + raw_vars["ansible_ssh_pass"] = become_pass + + extra_vars = json.dumps(raw_vars) # Execute Ansible playbook for each host subprocess.run(