There are several ways to achieve your goal depending on your exact requirement. Here is one to put you on track in a self explanatory playbook with intermediate debug. Note: for the example and legibility I limited the output to 2 networks with 2 ips each. Just change those figures to fit your needs.
---
- hosts: localhost
gather_facts: false
vars:
number_of_networks: 2
ips_per_network: 2
networks_list: "{{ range(0, number_of_networks) }}"
ips_list: "{{ range(1, ips_per_network + 1) }}"
networks_ips_product: "{{ networks_list | product(ips_list) }}"
ipa_base: "dc=whatever,dc=local"
tasks:
- name: Create a list of networks starting from 0
ansible.builtin.debug:
var: networks_list
- name: Create a list of ips starting from 1
ansible.builtin.debug:
var: ips_list
- name: Combine every network with every ip in a single list
ansible.builtin.debug:
var: networks_ips_product
- name: Loop on that list in a debug tasks which mimics your ldap task
vars:
network_it: "{{ item.0 }}"
ip_it: "{{ item.1 }}"
entry: "10{{ ip_it }}"
ip: "224.0.{{ network_it }}.{{ ip_it }}"
ldap_entry:
dn: entry={{ entry }},cn=multicast,{{ ipa_base }}
state: present
objectClass:
- multicastAddress
- top
attributes:
entry: "{{ entry }}"
network: "Network{{ network_it }}"
ipNumber: "{{ ip }}"
server_uri: localhost
bind_dn: "cn=Directory Manager"
bind_pw: "v3rys3cr3t"
ansible.builtin.debug:
var: ldap_entry
loop: "{{ networks_ips_product }}"
Running the above playbook gives:
PLAY [localhost] ***********************************************************************************************************************************************************************************************************************
TASK [Create a list of networks starting from 0] ***************************************************************************************************************************************************************************************
ok: [localhost] => {
"networks_list": [
0,
1
]
}
TASK [Create a list of ips starting from 1] ********************************************************************************************************************************************************************************************
ok: [localhost] => {
"ips_list": [
1,
2
]
}
TASK [Combine every network with every ip in a single list] ***************************************************************************************************************************************************************************************
ok: [localhost] => {
"networks_ips_product": [
[
0,
1
],
[
0,
2
],
[
1,
1
],
[
1,
2
]
]
}
TASK [Loop on that list in a debug tasks which mimics your ldap task] ******************************************************************************************************************************************************************
ok: [localhost] => (item=[0, 1]) => {
"ansible_loop_var": "item",
"item": [
0,
1
],
"ldap_entry": {
"attributes": {
"entry": "101",
"ipNumber": "224.0.0.1",
"network": "Network0"
},
"bind_dn": "cn=Directory Manager",
"bind_pw": "v3rys3cr3t",
"dn": "entry=101,cn=multicast,dc=whatever,dc=local",
"objectClass": [
"multicastAddress",
"top"
],
"server_uri": "localhost",
"state": "present"
}
}
ok: [localhost] => (item=[0, 2]) => {
"ansible_loop_var": "item",
"item": [
0,
2
],
"ldap_entry": {
"attributes": {
"entry": "102",
"ipNumber": "224.0.0.2",
"network": "Network0"
},
"bind_dn": "cn=Directory Manager",
"bind_pw": "v3rys3cr3t",
"dn": "entry=102,cn=multicast,dc=whatever,dc=local",
"objectClass": [
"multicastAddress",
"top"
],
"server_uri": "localhost",
"state": "present"
}
}
ok: [localhost] => (item=[1, 1]) => {
"ansible_loop_var": "item",
"item": [
1,
1
],
"ldap_entry": {
"attributes": {
"entry": "101",
"ipNumber": "224.0.1.1",
"network": "Network1"
},
"bind_dn": "cn=Directory Manager",
"bind_pw": "v3rys3cr3t",
"dn": "entry=101,cn=multicast,dc=whatever,dc=local",
"objectClass": [
"multicastAddress",
"top"
],
"server_uri": "localhost",
"state": "present"
}
}
ok: [localhost] => (item=[1, 2]) => {
"ansible_loop_var": "item",
"item": [
1,
2
],
"ldap_entry": {
"attributes": {
"entry": "102",
"ipNumber": "224.0.1.2",
"network": "Network1"
},
"bind_dn": "cn=Directory Manager",
"bind_pw": "v3rys3cr3t",
"dn": "entry=102,cn=multicast,dc=whatever,dc=local",
"objectClass": [
"multicastAddress",
"top"
],
"server_uri": "localhost",
"state": "present"
}
}
PLAY RECAP *****************************************************************************************************************************************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0