files precedence

Hi,

Following the principle of variable precedence, I am wondering why
there is no such concept for files.

Example:

I have the following playbooks:

- -- ansible-playbook-some_app ------
- - ansible-playbook-some_app
  - files
    - some_files
    - private_ssl_files <- not in the git repo, used for tests only
  - tasks
    - main.yml
  - test.yml <- playbook used for test
  - Vagrantfile <- VM used for test
  - .git
- -----------------------------------

^ this playbook is intended to be the most generic possible, I do not
want any host specific data in the folder layout, since it will be used
for a lot of different host.

- -- ansible-playbook-host ----------
- - ansible-playbook-host_1
  - files
    - private_ssl_files <- the ssl files for the host
  -roles
    - some_app <- git submodule of the previous playbook
    - other_app_1 <- git submodule
    - ...
  - the_rest_of_the_playbook_layout
- ------------------------------------

I only want submodules in my roles folder to avoid a mess and loosing
track of what is modified on my host. What I would like, is to be able
to put my ssl files for the host in the root files folder, and not in
the roles/some_app/files folder. It seems that by default ansible does
not allow this. Unlike the vars, there is no files precedence.

Is there a clean way to handle this?

I see a different use case of files (even templates) precedence, is it
a planned feature? Does it has been discussed earlier?

I am new to ansible, so it may be possible that I do not see the
ansible-way of doing it. Do not hesitate to point me to the revelant
discussion/doc/example-playbook :slight_smile:

Regards

- --
Mayeu
http://6x9.fr

I only want submodules in my roles folder to avoid a mess and loosing
track of what is modified on my host. What I would like, is to be able
to put my ssl files for the host in the root files folder, and not in
the roles/some_app/files folder. It seems that by default ansible does
not allow this. Unlike the vars, there is no files precedence.

src=../../{{ inventory_hostname }}/file.txt ?

Is there a clean way to handle this?

I see a different use case of files (even templates) precedence, is it
a planned feature? Does it has been discussed earlier?

Consider looking into "with_first_found" if you want to look into multiple
locations and have a default.

Thank you for your response.

src=../../{{ inventory_hostname }}/file.txt ?

Consider looking into "with_first_found" if you want to look into
multiple locations and have a default.

Both those solutions assumes that I know what is the path to the file,
wich may not be true. If the playbook may be a role of one playbook, or
a role of a role, wich then make it not always possible to know the
inclusion level.

By accident I discover something that allow me to do file precedence.
Basically, instead of putting src=<file_name> I used
src=files/<file_name>. By default Ansible use only `./files/<file_name>`
of the playbook, by adding `files/`, Ansible get the first <file_name>
found in a `files` folder, thus using precedence.

I made a little repository to illustrate this:
https://github.com/Mayeu/ansible-playbook-file_precedence_test

So, is it a bug, or a feature? If it is a bug, it should be promoted to
a feature, it is really handy to have file precedence when you try to
have generic playbook. If it is already a feature, I missed the part in
the doc specifying that :slight_smile:

- --
Mayeu
http://6x9.fr

Ansible looks in the files directory of the role first by design, yes.