Created
December 1, 2022 15:10
-
-
Save jpmens/d48c5223f28e78496bd221f458d72454 to your computer and use it in GitHub Desktop.
Ansible filter convert IP to arpaname
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# arpaname.py, (C)2022 by Jan-Piet Mens <[email protected]> | |
# Convert an IPv4 or IPv6 address in textual form into a string whose value is | |
# the reverse-map domain name of the address. | |
# | |
# - debug: msg="{{ "192.168.1.3" | arpaname }}" | |
# "3.1.168.192.in-addr.arpa." | |
# | |
# - debug: msg="{{ "2001:DB8::7" | arpaname }}" | |
# "7.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa." | |
import dns.reversename | |
def arpaname(ip_addr): | |
rev = dns.reversename.from_address(str(ip_addr)) | |
return str(rev) | |
class FilterModule(object): | |
def filters(self): | |
return { | |
'arpaname' : arpaname, | |
'revip' : arpaname, | |
} |
Author
jpmens
commented
Dec 1, 2022
TIL that | ansible.utils.ipaddr('revdns')
exists.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment