plugin-hostfiles rolle aus Zürich
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
L3D f1e34cd7a6
2 years ago
.gitignore .gitignore 2 years ago Host files lookup plugin 2 years ago Add readme 2 years ago

Host files plugin

Ansible lookup plugin implementing a host_files and group_files strategy.


Put the file anywhere Ansible can find it, for example within the ansible/lookup_plugins/ directory. Edit the configuration file ansible.cfg and add in the [defaults] section the entry lookup_plugins = ansible/lookup_plugins.

Usage example

Like with any lookup plugin, the general call syntax is:

'{{ lookup("hf", "interfaces.conf") }}'

where we want to look for a file named interfaces.conf and get its (absolute) file path for use in:

    src: '{{ lookup("hf", "interfaces.conf") }}'
    dest: '/etc/network/interfaces'

where we configure Debian network settings.

How it works

Within the global files directory two subdirectories named:

  • host_files
  • group_files

may exist. Within the host_files directory, subdirectories with a hostname or fqdn may exist. Within the group_files, subdirectories named after Ansible host groups may exist.

The plugin will search for a file with the given name within these directories in the following order:

  • the hostname as given by inventory_hostname_short
  • the fqdn as given by inventory_hostname
  • any group name from group_names
  • the group all
  • within the (role) default files directory

Note that the order among multiple groups is not guaranteed (for example from generic groups to specific subgroups).