Skip to content
Snippets Groups Projects
Commit b2591db8 authored by alexandr.benzonan's avatar alexandr.benzonan
Browse files

update readme vith variables

parent 6eb4f866
Branches
No related tags found
No related merge requests found
...@@ -89,11 +89,11 @@ iface eth0 inet static ...@@ -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 nous voulons pouvoir utiliser le même template pour nos différents appareils nous allons donc utiliser des variables
```bash ```bash
auto {{ifname}} auto {{all[group_names[0]].ifname}}
iface {{ifname}} inet static iface {{all[group_names[0]].ifname}} inet static
address {{ip}} address {{all[inventory_hostname].ip}}
netmask {{netmask}} netmask {{all.netmask}}
post-up ip route add default via {{gateway}} 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 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 ...@@ -142,39 +142,40 @@ iface eth0 inet static
comme précédemment il nous faut des variables comme précédemment il nous faut des variables
```bash ```bash
auto {{ifname}} auto {{all[group_names[0]].ifname}}
iface {{ifname}} inet static iface {{all[group_names[0]].ifname}} inet static
address {{ip}} address {{all[inventory_hostname].ip}}
netmask {{netmask}} netmask {{all.netmask}}
auto {{ifname2}} auto {{ifname2}}
iface {{ifname2}} inet static uto {{all['routers'].ifname2}}
address {{ip2}} iface {{all['routers'].ifname2}} inet static
netmask {{netmask}} address {{all[inventory_hostname].ip2}}
post-up ip route add 3.0.0.0/24 via {{gateway}} 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 J’avais indiqué que notre config serait utilisée pour tout les appareils nous allons donc ajouter des conditions
```bash ```bash
auto {{ifname}} auto {{all[group_names[0]].ifname}}
iface {{ifname}} inet static iface {{all[group_names[0]].ifname}} inet static
address {{ip}} address {{all[inventory_hostname].ip}}
netmask {{netmask}} netmask {{all.netmask}}
{% if type == "host" %} {% if group_names[0] == "hosts" %}
post-up ip route add default via {{gateway}} post-up ip route add default via {{all[inventory_hostname].gateway}}
{% endif %} {% endif %}
{% if type == "router" %}
auto {{ifname2}} {% if group_names[0] == "routers" %}
iface {{ifname2}} inet static auto {{all['routers'].ifname2}}
address {{ip2}} iface {{all['routers'].ifname2}} inet static
netmask {{netmask}} address {{all[inventory_hostname].ip2}}
netmask {{all.netmask}}
{% if inventory_hostname == "R1" %} {% 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 %} {% 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 %}
{% endif %} {% endif %}
``` ```
...@@ -322,26 +323,14 @@ on récupère la config et on l’utilise dans un template jinja2 ...@@ -322,26 +323,14 @@ on récupère la config et on l’utilise dans un template jinja2
```bash ```bash
[Interface] [Interface]
{% if inventory_hostname == "H1" %} Address = {{all[inventory_hostname].ip}}
Address = {{h1_ip}} ListenPort = {{all[inventory_hostname].port}}
ListenPort = {{h1_port}} PrivateKey = {{pk[inventory_hostname].private_key}}
PrivateKey = {{all.h1_private_key}}
{% else %}
Address = {{h2_ip}}
ListenPort = {{h2_port}}
PrivateKey = {{all.h2_private_key}}
{% endif %}
[Peer] [Peer]
{% if inventory_hostname == "H1" %} PublicKey = {{all[inventory_hostname].other_public_key}}
PublicKey = {{h2_public_key}} AllowedIPs = {{all[inventory_hostname].AllowedIPs}}
AllowedIPs = {{h1_AllowedIPs}} Endpoint = {{all[inventory_hostname].endpoint}}:{{all[inventory_hostname].other_port}}
Endpoint = {{h1_endpoint}}:{{h2_port}}
{% else %}
PublicKey = {{h1_public_key}}
AllowedIPs = {{h2_AllowedIPs}}
Endpoint = {{h2_endpoint}}:{{h1_port}}
{% endif %}
``` ```
ici aussi la config est la même pour H1 et H2 ici aussi la config est la même pour H1 et H2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment