Comment 7 for bug 1990513

Revision history for this message
Jack Zhang (zhan9san) wrote :

Hi

Would it be possible to add a new module to handle the directory feature?
Proposed new module name is 'File'.

I tried to add 'chownbyname' in 'ensure_dir' method directly, which will only change the ownership for parent directory only.

But I have some concerns.

As 'os.makedirs' will create directories recursively by default, we can not easily know which of them are newly created. So there would introduce much more logic to detect which directories is newly created and which exist already.

e.g.

- path: /home/ubuntu/foo/bar/baz/file-in.txt

We have to check whether all '/home/ubuntu/foo/bar/baz', '/home/ubuntu/foo/bar' and '/home/ubuntu/foo' exist. If all of them don't exist, we have to change ownership for all of them.

It is inspired by shixuantong (sxt1001)'s idea. If so, users have to ensure the directory exists first via 'file' module and then write out arbitrary content to files via 'Write Files' module.

Reference:
https://github.com/canonical/cloud-init/blob/94a00492b11995dd9278605eb29ee4b096ce3a90/cloudinit/util.py#L1795
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html#parameter-recurse