mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-26 22:51:23 -07:00
vault: check dir existence before creating a file (#40010)
This commit is contained in:
parent
22456a57de
commit
dccb0d035b
1 changed files with 6 additions and 0 deletions
|
@ -78,6 +78,7 @@ from ansible.module_utils.six import PY3, binary_type
|
||||||
# Note: on py2, this zip is izip not the list based zip() builtin
|
# 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.six.moves import zip
|
||||||
from ansible.module_utils._text import to_bytes, to_text, to_native
|
from ansible.module_utils._text import to_bytes, to_text, to_native
|
||||||
|
from ansible.utils.path import makedirs_safe
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from __main__ import display
|
from __main__ import display
|
||||||
|
@ -925,6 +926,11 @@ class VaultEditor:
|
||||||
def create_file(self, filename, secret, vault_id=None):
|
def create_file(self, filename, secret, vault_id=None):
|
||||||
""" create a new encrypted file """
|
""" 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
|
# FIXME: If we can raise an error here, we can probably just make it
|
||||||
# behave like edit instead.
|
# behave like edit instead.
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue