Christophe
(Christophe)
December 22, 2025, 10:55am
1
Hello all,
Is there a way to generate an IPv6 ULA /64 subnet subnet?
I’ve been looking in the docs but nowhere can I find how to do this.
Some Google-fu gave me this command, which works locally, but not when ran through ansible using ansible.builtin.shell:
printf “fd%x:%x:%x:%x::/64” “$(( $RANDOM/256 ))” “$RANDOM” “$RANDOM” “$RANDOM”
Anybody who has a solution or workaround for this?
U880D
December 22, 2025, 2:43pm
2
Considering that $RANDOM
is an internal Bash function (not a constant) that returns a pseudorandom integer in the range 0 - 32767
the almost exact equivalent to the given command
printf "fd%x:%x:%x:%x::/64\n" "$(( $RANDOM/256 ))" "$RANDOM" "$RANDOM" "$RANDOM"
resulting into a random output like
fd1:4dd9:8f1:6ea7::/64
would be in Ansible
---
- hosts: localhost
become: false
gather_facts: false
tasks:
- name: Generate an IPv6 Unique Local Address (ULA) /64 subnet
debug:
msg: "fd{{ '%02x' % ((127 | random) | int) }}:{{ '%x' % ((32767 | random) | int) }}:{{ '%x' % ((32767 | random) | int) }}:{{ '%x' % ((32767 | random) | int) }}::/64"
resulting into a random output of
TASK [Generate an IPv6 Unique Local Address (ULA) /64 subnet] ***
ok: [localhost] =>
msg: fd01:4dd9:8f1:6ea7::/64
by using Python Format with % within Jinja2 Template .
Christophe
(Christophe)
December 22, 2025, 4:01pm
3
Great, that seems to work!
Don’t think I would have ever found this myself.
system
(system)
Closed
January 21, 2026, 4:02pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.