# Selectively importing files based on variables (first\_available\_file)

**URL:** <https://forum.ansible.com/t/selectively-importing-files-based-on-variables-first-available-file/11462>\
**Category:** Ansible Project\
**Created:** [April 28, 2012, 2:33am UTC](https://forum.ansible.com/t/selectively-importing-files-based-on-variables-first-available-file/11462 "2012-04-28T02:33:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [April 28, 2012, 2:33am UTC](https://forum.ansible.com/t/selectively-importing-files-based-on-variables-first-available-file/11462/1 "2012-04-28T02:33:02Z")

</div>

Seth Vidal provided a very nice patch that allows us to conditionally  
pick a different source for a file based on an ansible, facter, or  
ohai fact. This is admittedly an advanced sort of thing, but I think  
it'll be pretty clear and I'm quite impressed by the syntax.

This can be used, for instance, to use the same playbook for different  
operating systems, where depending on the operating system you need a  
different configuration file.

I've included an example of what this looks like in a playbook here:

[https://github.com/ansible/ansible/blob/devel/examples/playbooks/selective\_file\_sources.yml](https://github.com/ansible/ansible/blob/devel/examples/playbooks/selective_file_sources.yml)

I'll note that that presently the best OS variable we have is  
ansible\_distribution\_version, which gives 6.2 for CentOS, so making a  
fact that includes the integer version is probably in order. Let me  
know if there are other facts you would like to use for conditionally  
chosing a template or copy file location.

This could also be used for the ability to optionally be able to  
override a file based on it's hostname, and then default to a value if  
there is no hostname specific configuration file.

I'm keeping all the documentation for 0.4 off the site until 0.4 goes  
out, so see the playbook example for now for how it works.

Enjoy shiny new features!

--Michael
