1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add playbook example for first_available_file

This commit is contained in:
Michael DeHaan 2012-04-26 23:03:14 -04:00
parent 3804910187
commit aa8ae85070
2 changed files with 29 additions and 0 deletions

View file

@ -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

View file

@ -391,6 +391,7 @@ class Runner(object):
# apply templating to source argument # apply templating to source argument
inject = self.setup_cache.get(conn.host,{}) inject = self.setup_cache.get(conn.host,{})
# FIXME: break duplicate code up into subfunction
# if we have first_available_file in our vars # if we have first_available_file in our vars
# look up the files and use the first one we find as src # look up the files and use the first one we find as src
if 'first_available_file' in self.module_vars: if 'first_available_file' in self.module_vars: