Fixes: #20986 blockinfile create undelying directory when create=true (#27961)

This commit is contained in:
Giovanni Sciortino 2018-02-06 16:48:15 +01:00 committed by Adam Miller
parent 14841e453a
commit fb2c0181c5

View file

@ -223,6 +223,12 @@ def main():
if not module.boolean(params['create']):
module.fail_json(rc=257,
msg='Path %s does not exist !' % path)
destpath = os.path.dirname(path)
if not os.path.exists(destpath) and not module.check_mode:
try:
os.makedirs(destpath)
except Exception as e:
module.fail_json(msg='Error creating %s Error code: %s Error description: %s' % (destpath, e[0], e[1]))
original = None
lines = []
else: