Ansible: Auto mkdirs when copying file

Created on 5 Aug 2013  ·  3Comments  ·  Source: ansible/ansible

An option should be added to create required directories when copying file if they don't exist.

For example, when copying pip.conf to $HOST/root/.pip/, we may meet following error:

msg: Destination directory /root/.pip does not exist

I think /root/.pip should be automatically created (or at least add an option and let the user decide.)

Most helpful comment

@mpdehaan it should set the default permissions for the directory. As it does in your example....you are not setting permissions for the directory, but allowing the defaults. Having to add this is annoying at best.

All 3 comments

I disagree with this, because you really do need to set a permissions for the directory as well as the file.

Just add a task before that says:

  • file: path=/some/dir/to/wherever state=directory

and consider passing ownership and mode parameters.

@mpdehaan it should set the default permissions for the directory. As it does in your example....you are not setting permissions for the directory, but allowing the defaults. Having to add this is annoying at best.

@mpdehaan so, maybe this should be re-opened?

Was this page helpful?
0 / 5 - 0 ratings