diff --git a/cloudinit/util.py b/cloudinit/util.py index 8025f4d51c4..e2f04a40209 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1884,7 +1884,11 @@ def ensure_dir(path, mode=None, user=None, group=None): # Get non existed parent dir first before they are created. non_existed_parent_dir = get_non_exist_parent_dir(path) # Make the dir and adjust the mode - with SeLinuxGuard(os.path.dirname(path), recursive=True): + dir_name = os.path.dirname(path) + selinux_recursive = True + if dir_name == "/": + selinux_recursive = False + with SeLinuxGuard(dir_name, recursive=selinux_recursive): os.makedirs(path) chmod(path, mode) # Change the ownership