diff --git a/README.md b/README.md index 242ac326d47b56d52d96683bc78815af246960c4..7d8a969d1e8fcbad20b702ad6b16e082558fc0af 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,11 @@ iface eth0 inet static nous voulons pouvoir utiliser le même template pour nos différents appareils nous allons donc utiliser des variables ```bash -auto {{ifname}} -iface {{ifname}} inet static - address {{ip}} - netmask {{netmask}} - post-up ip route add default via {{gateway}} +auto {{all[group_names[0]].ifname}} +iface {{all[group_names[0]].ifname}} inet static + address {{all[inventory_hostname].ip}} + netmask {{all.netmask}} + post-up ip route add default via {{all[inventory_hostname].gateway}} ``` la config de H2 est identique mais avec 3.0.0.3 comme ip et 3.0.0.2 comme gateway @@ -142,39 +142,40 @@ iface eth0 inet static comme précédemment il nous faut des variables ```bash -auto {{ifname}} -iface {{ifname}} inet static - address {{ip}} - netmask {{netmask}} +auto {{all[group_names[0]].ifname}} +iface {{all[group_names[0]].ifname}} inet static + address {{all[inventory_hostname].ip}} + netmask {{all.netmask}} auto {{ifname2}} -iface {{ifname2}} inet static - address {{ip2}} - netmask {{netmask}} - post-up ip route add 3.0.0.0/24 via {{gateway}} +uto {{all['routers'].ifname2}} +iface {{all['routers'].ifname2}} inet static + address {{all[inventory_hostname].ip2}} + netmask {{all.netmask}} + post-up ip route add 3.0.0.0/24 nexthop via {{all[inventory_hostname].gateway}} ``` J’avais indiqué que notre config serait utilisée pour tout les appareils nous allons donc ajouter des conditions ```bash -auto {{ifname}} -iface {{ifname}} inet static - address {{ip}} - netmask {{netmask}} +auto {{all[group_names[0]].ifname}} +iface {{all[group_names[0]].ifname}} inet static + address {{all[inventory_hostname].ip}} + netmask {{all.netmask}} -{% if type == "host" %} - post-up ip route add default via {{gateway}} +{% if group_names[0] == "hosts" %} + post-up ip route add default via {{all[inventory_hostname].gateway}} {% endif %} -{% if type == "router" %} -auto {{ifname2}} -iface {{ifname2}} inet static - address {{ip2}} - netmask {{netmask}} +{% if group_names[0] == "routers" %} +auto {{all['routers'].ifname2}} +iface {{all['routers'].ifname2}} inet static + address {{all[inventory_hostname].ip2}} + netmask {{all.netmask}} {% if inventory_hostname == "R1" %} - post-up ip route add 3.0.0.0/24 nexthop via {{gateway}} + post-up ip route add 3.0.0.0/24 nexthop via {{all[inventory_hostname].gateway}} {% else %} - post-up ip route add 1.0.0.0/24 nexthop via {{gateway}} + post-up ip route add 1.0.0.0/24 nexthop via {{all[inventory_hostname].gateway}} {% endif %} {% endif %} ``` @@ -322,26 +323,14 @@ on récupère la config et on l’utilise dans un template jinja2 ```bash [Interface] -{% if inventory_hostname == "H1" %} -Address = {{h1_ip}} -ListenPort = {{h1_port}} -PrivateKey = {{all.h1_private_key}} -{% else %} -Address = {{h2_ip}} -ListenPort = {{h2_port}} -PrivateKey = {{all.h2_private_key}} -{% endif %} +Address = {{all[inventory_hostname].ip}} +ListenPort = {{all[inventory_hostname].port}} +PrivateKey = {{pk[inventory_hostname].private_key}} [Peer] -{% if inventory_hostname == "H1" %} -PublicKey = {{h2_public_key}} -AllowedIPs = {{h1_AllowedIPs}} -Endpoint = {{h1_endpoint}}:{{h2_port}} -{% else %} -PublicKey = {{h1_public_key}} -AllowedIPs = {{h2_AllowedIPs}} -Endpoint = {{h2_endpoint}}:{{h1_port}} -{% endif %} +PublicKey = {{all[inventory_hostname].other_public_key}} +AllowedIPs = {{all[inventory_hostname].AllowedIPs}} +Endpoint = {{all[inventory_hostname].endpoint}}:{{all[inventory_hostname].other_port}} ``` ici aussi la config est la même pour H1 et H2