From 48b0ac84061a2c73d08726ccabf4dd60c506aab3 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 24 Sep 2024 21:30:22 +0200 Subject: ipam-generate-tf --- ansible/group_vars/all/ipam.yml | 6 ++--- ansible/plays/ipam-generate-tf.yml | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 ansible/plays/ipam-generate-tf.yml (limited to 'ansible') diff --git a/ansible/group_vars/all/ipam.yml b/ansible/group_vars/all/ipam.yml index 991bf81..452a79e 100644 --- a/ansible/group_vars/all/ipam.yml +++ b/ansible/group_vars/all/ipam.yml @@ -7,16 +7,14 @@ ipam6: networks: bitraf_dn42: - range: "fdb1:4242:3538:::/48" + range: "fdb1:4242:3538::/48" tnet_dn42: range: "fdb1:4242:3538:2000::/52" conflatorio_dn42: description: Internal network on host range: "fdb1:4242:3538:2001::/64" hosts: - conflatorio-ix: "fdb1:4242:3538:2001::ffff/64" - conflatorio_docker: - range: "fdb1:4242:3538:2001:1001::/112" + conflatorio: "fdb1:4242:3538:2001::ffff/64" node1_dn42: range: "fdb1:4242:3538:2002::/64" node2_dn42: diff --git a/ansible/plays/ipam-generate-tf.yml b/ansible/plays/ipam-generate-tf.yml new file mode 100644 index 0000000..f905b51 --- /dev/null +++ b/ansible/plays/ipam-generate-tf.yml @@ -0,0 +1,51 @@ +- hosts: localhost + gather_facts: no + connection: local + tasks: + - name: Generate terraform/ipam6/ipam6.tf + register: tf + copy: + dest: ../../terraform/ipam6/ipam6.tf + content: | + output "networks" { + value = { + {% for name, network in ipam6.networks.items() %} + {% if not (network.range | ipv6) %} + Invalid network: {{ network.range }} + {% endif %} + {{ name }} = { + {% if network.description|default("") %} + description = "{{ network.description }}" + {% endif %} + range = "{{ network.range }}" + address = "{{ network.range|ipaddr("network") }}" + prefix = "{{ network.range|ipaddr("prefix") }}" + {% set hosts = network.hosts|default({}) %} + hosts = { + {% for name, addr in hosts.items() %} + {{ name }} = { + address: "{{ addr|ipaddr("address") }}" + prefix: "{{ addr|ipaddr("prefix") }}" + } + {% endfor %} + } + } + {% endfor %} + } + } + + output "hosts" { + value = { + {% for name, network in ipam6.networks.items() %} + {% set hosts = network.hosts|default({}) %} + {% for name, addr in hosts.items() %} + {{ name }} = { + address: "{{ addr|ipaddr("address") }}" + prefix: "{{ addr|ipaddr("prefix") }}" + } + {% endfor %} + {% endfor %} + } + } + - shell: terraform fmt ../../terraform/ipam6/ipam6.tf + when: "tf.changed" -- cgit v1.2.3