Playbooks to a new Lilik
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.

18 lines
602 B

  1. from ansible.errors import AnsibleError, AnsibleParserError
  2. def ip_from_inventory(hostvars, hostname):
  3. """
  4. replace this ``{{ hostvars[hostname]['ansible_host'] }}``
  5. with something nicer such as `` {{ hostvars | ip_from_inventory(hostname) }}``
  6. """
  7. if not hostname in hostvars:
  8. raise AnsibleError('<ip_from_inventory> hostname "{hostname}" not found in inventory'.format(hostname=hostname))
  9. return hostvars[hostname]['ansible_host']
  10. class FilterModule(object):
  11. def filters(self):
  12. return {
  13. 'ip_from_inventory': ip_from_inventory,
  14. }