blockinfile: do not crash when filename has no path (#81638)

* Do not crash when filename has no path.

* Clean up file after test.
pull/82874/head
Felix Fontein 8 months ago committed by GitHub
parent 0c9f1989a7
commit e659c23bf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
bugfixes:
- "blockinfile - when ``create=true`` is used with a filename without path, the module crashed (https://github.com/ansible/ansible/pull/81638)."

@ -268,7 +268,7 @@ def main():
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:
if destpath and not os.path.exists(destpath) and not module.check_mode:
try:
os.makedirs(destpath)
except OSError as e:

@ -30,3 +30,17 @@
- empty_test_2 is changed
- "'Block removed' in empty_test_2.msg"
- empty_test_stat.stat.size == 0
- block:
- name: Create file in current directory
blockinfile:
path: "empty.txt"
block: Hello.
state: present
create: yes
always:
- name: Remove file
file:
path: "empty.txt"
state: absent

Loading…
Cancel
Save