From bd0066d6217605dbe98717406af074ed05962bc4 Mon Sep 17 00:00:00 2001 From: Jesper Geertsen Jonsson Date: Mon, 7 Dec 2015 21:52:41 +0100 Subject: [PATCH] Adds support for converting a MAC address to an integer. Example: --- - hosts: local tasks: - set_fact: mac_str="52:54:00:00:00:00" - set_fact: base_mac="{{ mac_str | macaddr('int') }}" - debug: msg="{{ (base_mac|int + 257) | macaddr('linux') }}" # 52:54:00:00:01:01 --- lib/ansible/plugins/filter/ipaddr.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ansible/plugins/filter/ipaddr.py b/lib/ansible/plugins/filter/ipaddr.py index bfcf32af051..4afe4222dc8 100644 --- a/lib/ansible/plugins/filter/ipaddr.py +++ b/lib/ansible/plugins/filter/ipaddr.py @@ -228,6 +228,9 @@ def _bool_hwaddr_query(v): if v: return True +def _int_hwaddr_query(v): + return int(v) + def _cisco_query(v): v.dialect = netaddr.mac_cisco return str(v) @@ -637,6 +640,7 @@ def hwaddr(value, query = '', alias = 'hwaddr'): '': _empty_hwaddr_query, 'bare': _bare_query, 'bool': _bool_hwaddr_query, + 'int': _int_hwaddr_query, 'cisco': _cisco_query, 'eui48': _win_query, 'linux': _linux_query,