From 115d91069c5a551993e59ff06bcbae01ec9de6be Mon Sep 17 00:00:00 2001 From: Joseph Price Date: Wed, 1 Mar 2017 11:43:48 +0000 Subject: [PATCH] CLI: unfrack --private-key path Relative paths can break the synchronize plugin when the playbook is not in the current working directory. Fixes: ansible/ansible#22695 (cherry picked from commit ed15ba1b3c775df5cdd59d658bca850603cdce64) --- lib/ansible/cli/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index a271043133a..ff8743c15ee 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -36,6 +36,7 @@ from ansible import constants as C from ansible.compat.six import with_metaclass from ansible.errors import AnsibleError, AnsibleOptionsError from ansible.module_utils._text import to_bytes, to_text +from ansible.utils.path import unfrackpath try: from __main__ import display @@ -265,6 +266,10 @@ class CLI(with_metaclass(ABCMeta, object)): def expand_tilde(option, opt, value, parser): setattr(parser.values, option.dest, os.path.expanduser(value)) + @staticmethod + def unfrack_path(option, opt, value, parser): + setattr(parser.values, option.dest, unfrackpath(value)) + @staticmethod def expand_paths(option, opt, value, parser): """optparse action callback to convert a PATH style string arg to a list of path strings. @@ -339,7 +344,8 @@ class CLI(with_metaclass(ABCMeta, object)): connect_group.add_option('-k', '--ask-pass', default=C.DEFAULT_ASK_PASS, dest='ask_pass', action='store_true', help='ask for connection password') connect_group.add_option('--private-key','--key-file', default=C.DEFAULT_PRIVATE_KEY_FILE, dest='private_key_file', - help='use this file to authenticate the connection') + help='use this file to authenticate the connection', + action="callback", callback=CLI.unfrack_path, type=str) connect_group.add_option('-u', '--user', default=C.DEFAULT_REMOTE_USER, dest='remote_user', help='connect as this user (default=%s)' % C.DEFAULT_REMOTE_USER) connect_group.add_option('-c', '--connection', dest='connection', default=C.DEFAULT_TRANSPORT,