ipaddr cidr_lookup

21 views
Skip to first unread message

Ryan Merolle

unread,
Jun 15, 2020, 7:27:38 PM6/15/20
to Ansible Project
Anyone use this filter function?  It seems like a lookup to see if an IP or subnet is a member of a larger prefix.

Scott Sturdivant

unread,
Jun 15, 2020, 7:55:25 PM6/15/20
to Ansible Project
Hi,

There are some great examples on the ipaddr filter's documentation page: https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters_ipaddr.html#playbooks-filters-ipaddr

Yes, one of the things you can do is check to see if an IP belongs to a subnet.

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b9d7048d-2bad-4bdc-a365-9909fb77ba38o%40googlegroups.com.

Ryan Merolle

unread,
Jun 15, 2020, 7:58:04 PM6/15/20
to Ansible Project
Hello Scott,

I’m very familiar with the documented functions of the ipaddr filter. If you look at the link you just sent cidr_lookup is not a documented function, but it is listed in the source code of the filter as I linked to in my original post.

Thanks!

Scott Sturdivant

unread,
Jun 15, 2020, 8:14:18 PM6/15/20
to Ansible Project
I think what you're asking for can be found by looking at the example for "By specifying a network range as a query, you can check if a given value is in that range:" in the docs.

An example playbook:

---
- hosts: localhost
  connection: local
  tasks:

    - debug:
        msg: belongs
      when: item | ipaddr('192.168.0.0/8')
      loop:
        - 192.168.0.45
        - 192.1.0.4/24
        - 127.0.0.1


Hope that helps!

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.

Ryan Merolle

unread,
Jun 15, 2020, 10:05:04 PM6/15/20
to Ansible Project
Scott,

I appreciate your patience here.  Even when I said I am very familiar with the document, you pressed on and pointed me to the item that was right in front of my face!  That worked perfectly

Thanks!


On Monday, June 15, 2020 at 8:14:18 PM UTC-4, Scott Sturdivant wrote:
I think what you're asking for can be found by looking at the example for "By specifying a network range as a query, you can check if a given value is in that range:" in the docs.

An example playbook:

---
- hosts: localhost
  connection: local
  tasks:

    - debug:
        msg: belongs
      when: item | ipaddr('192.168.0.0/8')
      loop:
        - 192.168.0.45
        - 192.1.0.4/24
        - 127.0.0.1


Hope that helps!

On Mon, Jun 15, 2020 at 5:58 PM Ryan Merolle <Ryan....@gmail.com> wrote:
Hello Scott,

I’m very familiar with the documented functions of the ipaddr filter.  If you look at the link you just sent cidr_lookup is not a documented function, but it is listed in the source code of the filter as I linked to in my original post.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages