Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract interface identifiers from addresses and create addresses from interface identifiers #360

Open
MPStudyly opened this issue Jul 1, 2024 · 0 comments
Labels

Comments

@MPStudyly
Copy link

SUMMARY

As we recently recreated our whole network as IPv6 only, we were surprised to have to rely on string editing to be able to fetch host parts/interface identifiers from complete addresses. Similar thing goes for address construction, where we have to rely on hex number as string to int conversion in conjunction with the nthhost filter to generate full addresses.

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

What we'd like to have is a parameter within the ipaddr filter, that allows to grab the interface identifier as ::xxxx:xxxx:xxxx:xxxx address. E.g.: "2001:db8::1/64" | ansible.utils.ipaddr('identifier') resulting in "::1" optionally, when the prefix size is omitted on the address a default of 64 could be assumed or a certain size could be given via named parameter, e.g.: "2001:db8:1:1::1" | ansible.utils.ipaddr('identifier', prefix_size=48) resulting in "0:0:0:1::1".
To build addresses, something like an "addr_from" filter could be helpful to create addresses from interface identifiers and subnets.

ADDITIONAL INFORMATION

Grabbing the interface identifies would be helpful in static IP configurations where you want to fetch data specified in a separate dict and look that up by interface identifier. Especially for HA router configurations this makes a lot of sense, as they will "share" a common identifier.
Building addresses out of identifiers allows easy dynamic address creation by specifying an identifier per host in the inventory and building addresses of that.

port_fetched_from_other_dict: >-
  {{ "port": (server.network.ipv6
              | selectattr('interface_identifier', 'eq', ('2001:db8:1:1::1' | ansible.utils.ipaddr('identifier', prefix_size=48))
              | first).port }}

static_routes:
  - address_families:
      - afi: "ipv6"
        routes:
          - dest: "::/0" # default route
            next_hops:
              - forward_router_address: "{{ '::1' | ansible.utils.addr_from(subnet='2001:db8::/64') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants