From aa8ae8507084d6901237089ebd801d7a66ab2127 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 26 Apr 2012 23:03:14 -0400 Subject: [PATCH] Add playbook example for first_available_file --- examples/playbooks/selective_file_sources.yml | 28 +++++++++++++++++++ lib/ansible/runner.py | 1 + 2 files changed, 29 insertions(+) create mode 100644 examples/playbooks/selective_file_sources.yml diff --git a/examples/playbooks/selective_file_sources.yml b/examples/playbooks/selective_file_sources.yml new file mode 100644 index 00000000000..0dd346985ee --- /dev/null +++ b/examples/playbooks/selective_file_sources.yml @@ -0,0 +1,28 @@ +--- +# this is an example of how to template a file over using some variables derived +# from the system. For instance, if you wanted to have different configuration +# templates by OS version, this is a neat way to do it. Any Ansible facts, facter facts, +# or ohai facts could be used to do this. + +- hosts: all + + tasks: + + - name: template a config file + action: template dest=/etc/imaginary_file.conf + first_available_file: + + # first see if we have a file for this specific host + - /srv/whatever/{{ ansible_hostname }}.conf + + # next try to load something like CentOS6.2.conf + - /srv/whatever/{{ ansible_distribution }}{{ ansible_distribution_version }}.conf + + # next see if there's a CentOS.conf + - /srv/whatever/{{ ansible_distribution }}.conf + + # finally give up and just use something generic + - /srv/whatever/default + + + diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index 715f488bf22..8982905bf8b 100644 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -391,6 +391,7 @@ class Runner(object): # apply templating to source argument inject = self.setup_cache.get(conn.host,{}) + # FIXME: break duplicate code up into subfunction # if we have first_available_file in our vars # look up the files and use the first one we find as src if 'first_available_file' in self.module_vars: