[RM-11694] Add optional directory to write_file()
This is mostly for testing purposes. The method has no way to
specify a directory independently from the file name, which it
makes it difficult to use with automated tests. It will get
refactored more later, but for now add a new kwarg that pass
in a dir to write to. Since a lot of callers are passing in
absolute paths (.e.g. "/etc/ceph/keyring"), we look for the
beginning slash and chop it off so that we can use os.path.join()
and write into something like /tmp/etc/ceph.
Signed-off-by: Travis Rhoden <trhoden@redhat.com>
(cherry picked from commit
628bd9ed6bfb84821ba7d2240cc41a8783cc4617)