aboutsummaryrefslogtreecommitdiff
path: root/ansible/plays
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2024-09-24 21:30:22 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2024-09-24 21:30:22 +0200
commit48b0ac84061a2c73d08726ccabf4dd60c506aab3 (patch)
tree44c6d4fc7750db0aec3ec2e3457b0954c9e6b9fc /ansible/plays
parent503ac9cad8bc348a31f23d2a721118eb1ce4653d (diff)
downloadinfra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.gz
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.bz2
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.tar.xz
infra-48b0ac84061a2c73d08726ccabf4dd60c506aab3.zip
ipam-generate-tf
Diffstat (limited to 'ansible/plays')
-rw-r--r--ansible/plays/ipam-generate-tf.yml51
1 files changed, 51 insertions, 0 deletions
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"