From 05ca8286197e11fd1b5babf980537789c726ed09 Mon Sep 17 00:00:00 2001 From: Cyril Jouve Date: Tue, 9 Oct 2018 00:35:05 +0200 Subject: [PATCH] create sources.list.d directory if needed (#36981) --- lib/ansible/modules/packaging/os/apt_repository.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ansible/modules/packaging/os/apt_repository.py b/lib/ansible/modules/packaging/os/apt_repository.py index 20b83ce108d..2d4a658822f 100644 --- a/lib/ansible/modules/packaging/os/apt_repository.py +++ b/lib/ansible/modules/packaging/os/apt_repository.py @@ -282,6 +282,11 @@ class SourcesList(object): for filename, sources in list(self.files.items()): if sources: d, fn = os.path.split(filename) + try: + os.makedirs(d) + except OSError as err: + if not os.path.isdir(d): + self.module.fail_json("Failed to create directory %s: %s" % (d, to_native(err))) fd, tmp_path = tempfile.mkstemp(prefix=".%s-" % fn, dir=d) f = os.fdopen(fd, 'w')