From be947e52665106ceceffc596ab6cb377dfa9e554 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Mon, 22 Apr 2013 23:57:20 -0400 Subject: [PATCH] Resolve merge conflict --- bin/ansible | 9 ++------- bin/ansible-playbook | 9 ++------- lib/ansible/utils/__init__.py | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/bin/ansible b/bin/ansible index d23c732260b..61806cc9dc3 100755 --- a/bin/ansible +++ b/bin/ansible @@ -20,7 +20,6 @@ ######################################################## import sys -import getpass from ansible.runner import Runner import ansible.constants as C @@ -101,13 +100,9 @@ class Cli(object): sshpass = None sudopass = None options.ask_pass = options.ask_pass or C.DEFAULT_ASK_PASS - if options.ask_pass: - sshpass = getpass.getpass(prompt="SSH password: ") options.ask_sudo_pass= options.ask_sudo_pass or C.DEFAULT_ASK_SUDO_PASS - if options.ask_sudo_pass: - sudopass = getpass.getpass(prompt="sudo password: ") - options.sudo = True - if options.sudo_user: + ( sshpass, sudopass ) = utils.ask_passwords(ask_pass=options.ask_pass, ask_sudo_pass=options.ask_sudo_pass) + if options.sudo_user or options.ask_sudo_pass: options.sudo = True options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER if options.tree: diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 5bcdb0cd635..a241b8e9963 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -19,7 +19,6 @@ ####################################################### import sys -import getpass import os import ansible.playbook @@ -93,13 +92,9 @@ def main(args): sudopass = None if not options.listhosts and not options.syntax and not options.listtasks: options.ask_pass = options.ask_pass or C.DEFAULT_ASK_PASS - if options.ask_pass: - sshpass = getpass.getpass(prompt="SSH password: ") options.ask_sudo_pass = options.ask_sudo_pass or C.DEFAULT_ASK_SUDO_PASS - if options.ask_sudo_pass: - sudopass = getpass.getpass(prompt="sudo password: ") - options.sudo = True - if options.sudo_user: + ( sshpass, sudopass ) = utils.ask_passwords(ask_pass=options.ask_pass, ask_sudo_pass=options.ask_sudo_pass) + if options.sudo_user or options.ask_sudo_pass: options.sudo = True options.sudo_user = options.sudo_user or C.DEFAULT_SUDO_USER extra_vars = utils.parse_kv(options.extra_vars) diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py index 325c3e7fcb1..7a737acffeb 100644 --- a/lib/ansible/utils/__init__.py +++ b/lib/ansible/utils/__init__.py @@ -38,6 +38,7 @@ import random import difflib import warnings import traceback +import getpass VERBOSITY=0 @@ -496,6 +497,22 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, return parser +def ask_passwords(ask_pass=False, ask_sudo_pass=False): + sshpass = None + sudopass = None + sudo_prompt = "sudo password: " + + if ask_pass: + sshpass = getpass.getpass(prompt="SSH password: ") + sudo_prompt = "sudo password [defaults to SSH password]: " + + if ask_sudo_pass: + sudopass = getpass.getpass(prompt=sudo_prompt) + if ask_pass and sudopass == '': + sudopass = sshpass + + return (sshpass, sudopass) + def do_encrypt(result, encrypt, salt_size=None, salt=None): if PASSLIB_AVAILABLE: try: