diff --git a/lib/ansible/cli/scripts/ansible_cli_stub.py b/lib/ansible/cli/scripts/ansible_cli_stub.py index 03891b728f5..231c11cd5eb 100755 --- a/lib/ansible/cli/scripts/ansible_cli_stub.py +++ b/lib/ansible/cli/scripts/ansible_cli_stub.py @@ -25,6 +25,7 @@ __metaclass__ = type __requires__ = ['ansible'] +import errno import os import shutil import sys @@ -100,6 +101,17 @@ if __name__ == '__main__': else: raise + b_ansible_dir = os.path.expanduser(os.path.expandvars(b"~/.ansible")) + try: + os.mkdir(b_ansible_dir, 0o700) + except OSError as exc: + if exc.errno != errno.EEXIST: + display.warning("Failed to create the directory '%s': %s" + % (to_text(b_ansible_dir, errors='surrogate_or_replace'), + to_text(exc, errors='surrogate_or_replace'))) + else: + display.debug("Created the '%s' directory" % to_text(b_ansible_dir, errors='surrogate_or_replace')) + try: args = [to_text(a, errors='surrogate_or_strict') for a in sys.argv] except UnicodeError: