Skip to content

Commit

Permalink
vault: check dir existence before creating a file (ansible#40010)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrizek authored May 11, 2018
1 parent 22456a5 commit dccb0d0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/ansible/parsing/vault/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
# Note: on py2, this zip is izip not the list based zip() builtin
from ansible.module_utils.six.moves import zip
from ansible.module_utils._text import to_bytes, to_text, to_native
from ansible.utils.path import makedirs_safe

try:
from __main__ import display
Expand Down Expand Up @@ -925,6 +926,11 @@ def decrypt_file(self, filename, output_file=None):
def create_file(self, filename, secret, vault_id=None):
""" create a new encrypted file """

dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
display.warning("%s does not exist, creating..." % dirname)
makedirs_safe(dirname)

# FIXME: If we can raise an error here, we can probably just make it
# behave like edit instead.
if os.path.isfile(filename):
Expand Down

0 comments on commit dccb0d0

Please sign in to comment.