From 62a00a877e4b35eda5be668fef75bbd73603f800 Mon Sep 17 00:00:00 2001
From: shirenn <shirenn@crans.org>
Date: Fri, 25 Jun 2021 11:29:14 +0200
Subject: [PATCH] [ethercalc] PEPCRANSED

---
 group_vars/ethercalc.yml                                      | 2 ++
 host_vars/ethercalc.adm.crans.org.yml                         | 3 ---
 plays/ethercalc.yml                                           | 2 ++
 roles/ethercalc/templates/systemd/system/ethercalc.service.j2 | 2 +-
 4 files changed, 5 insertions(+), 4 deletions(-)
 create mode 100644 group_vars/ethercalc.yml

diff --git a/group_vars/ethercalc.yml b/group_vars/ethercalc.yml
new file mode 100644
index 00000000..bbcecf6f
--- /dev/null
+++ b/group_vars/ethercalc.yml
@@ -0,0 +1,2 @@
+glob_ethercalc:
+  ip: "{{ query('ldap', 'ip', ansible_hostname, 'adm') | ipv4 | first }}"
diff --git a/host_vars/ethercalc.adm.crans.org.yml b/host_vars/ethercalc.adm.crans.org.yml
index 78460542..2eb6f993 100644
--- a/host_vars/ethercalc.adm.crans.org.yml
+++ b/host_vars/ethercalc.adm.crans.org.yml
@@ -2,6 +2,3 @@
 interfaces:
   adm: eth0
   srv_nat: eth1
-
-ethercalc:
-  ipv4: '172.16.10.133'
diff --git a/plays/ethercalc.yml b/plays/ethercalc.yml
index f7a6a03f..3b8102c8 100755
--- a/plays/ethercalc.yml
+++ b/plays/ethercalc.yml
@@ -1,5 +1,7 @@
 #!/usr/bin/env ansible-playbook
 ---
 - hosts: ethercalc
+  vars:
+    ethercalc: "{{ glob_ethercalc | default({}) | combine(loc_ethercalc | default({})) }}"
   roles:
     - ethercalc
diff --git a/roles/ethercalc/templates/systemd/system/ethercalc.service.j2 b/roles/ethercalc/templates/systemd/system/ethercalc.service.j2
index 7f251cb5..f82fa90b 100644
--- a/roles/ethercalc/templates/systemd/system/ethercalc.service.j2
+++ b/roles/ethercalc/templates/systemd/system/ethercalc.service.j2
@@ -11,7 +11,7 @@ RestartSec=3
 User=redis
 Group=redis
 PIDFile=/var/run/ethercalc.pid
-ExecStart=/usr/bin/ethercalc --host {{ ethercalc.ipv4 }} --port 8000
+ExecStart=/usr/bin/ethercalc --host {{ ethercalc.ip }} --port 8000
 
 [Install]
 WantedBy=multi-user.target
-- 
GitLab