Skip to content

Instantly share code, notes, and snippets.

@zircote
Last active August 29, 2015 13:57
Show Gist options
  • Save zircote/9794700 to your computer and use it in GitHub Desktop.
Save zircote/9794700 to your computer and use it in GitHub Desktop.
ansible filters
# !/usr/bin/env python
"""
Example Usage:
---
- debug: msg="{{ ansible_eth0.ipv4.address | ip2long }}"
"""
from socket import inet_aton
from struct import unpack
def ip2long(ip):
return unpack("!L", inet_aton(ip))[0]
class FilterModule(object):
def filters(self):
return {"ip2long": ip2long}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment