Ensure that initial setup in creating the key directory for ansible
accelerate mode keys, and generation/storage of the key for a
particular host are completed in a multiprocess safe manner.
Creating directories/files and then assigning permissions and contents
to them means that paths may exist and satisfy the os.path.exists()
method in python for other processes before they are usable.
Use a combination of locking around operations with use of unique named
files and an OS file system move to ensure that the conditions of
checking whether a file or directory exists, where it is potentially
created by another thread, will only succeed when the file has both the
correct contents and permissions.
Fixes#13850
raiseAnsibleError('Incorrect permissions on the key file for this host. Use `chmod 0%o%s` to correct this issue.'%(int(C.ACCELERATE_KEYS_FILE_PERMS,8),key_path))
fh=open(key_path)
key=AesKey.Read(fh.read())
fh.close()
returnkey
# avoid race with multiple forks trying to create key
# but limit when locking is needed to creation only
raiseAnsibleError('Incorrect permissions on the key file for this host. Use `chmod 0%o%s` to correct this issue.'%(int(C.ACCELERATE_KEYS_FILE_PERMS,8),key_path))