Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab3_Ansible
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
alexandr.benzonan
lab3_Ansible
Commits
b2591db8
Commit
b2591db8
authored
2 years ago
by
alexandr.benzonan
Browse files
Options
Downloads
Patches
Plain Diff
update readme vith variables
parent
6eb4f866
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+33
-44
33 additions, 44 deletions
README.md
with
33 additions
and
44 deletions
README.md
+
33
−
44
View file @
b2591db8
...
@@ -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]
==
"host
s
"
%
}
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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment