Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
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
Releases
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
ISC3
vres
ansible
Commits
03f42019
Verified
Commit
03f42019
authored
2 months ago
by
iliya.saroukha
Browse files
Options
Downloads
Patches
Plain Diff
feat: first playbook "really" finished, todo ping task between H1 and H2
parent
0c0c1c3c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
playbooks/first.play.yml
+45
-67
45 additions, 67 deletions
playbooks/first.play.yml
playbooks/templates/netconfig.j2
+17
-0
17 additions, 0 deletions
playbooks/templates/netconfig.j2
with
62 additions
and
67 deletions
playbooks/first.play.yml
+
45
−
67
View file @
03f42019
...
...
@@ -3,98 +3,76 @@
hosts
:
all
become
:
true
vars
:
gns3_host
s
:
interface
s
:
H1
:
interfaces
:
-
name
:
"
eth0"
address
:
"
1.0.0.3"
netmask
:
"
255.255.255.0"
gateway
:
"
1.0.0.1"
-
name
:
"
eth0"
address
:
"
1.0.0.3"
netmask
:
"
255.255.255.0"
gateway
:
"
1.0.0.1"
H2
:
-
name
:
"
eth0"
address
:
"
3.0.0.3"
netmask
:
"
255.255.255.0"
gateway
:
"
3.0.0.2"
R1
:
interfaces
:
-
name
:
eth1
address
:
"
1.0.0.1"
netmask
:
"
255.255.255.0"
-
name
:
eth0
address
:
"
2.0.0.1"
netmask
:
"
255.255.255.0"
routes
:
-
network
:
"
3.0.0.0/24"
via
:
"
2.0.0.2"
-
name
:
eth1
address
:
"
1.0.0.1"
netmask
:
"
255.255.255.0"
-
name
:
eth0
address
:
"
2.0.0.1"
netmask
:
"
255.255.255.0"
R2
:
interfaces
:
-
name
:
eth0
address
:
"
2.0.0.2"
netmask
:
"
255.255.255.0"
-
name
:
eth1
address
:
"
3.0.0.2"
netmask
:
"
255.255.255.0"
routes
:
-
network
:
"
1.0.0.0/24"
via
:
"
2.0.0.1"
-
name
:
eth0
address
:
"
2.0.0.2"
netmask
:
"
255.255.255.0"
-
name
:
eth1
address
:
"
3.0.0.2"
netmask
:
"
255.255.255.0"
H2
:
interfaces
:
-
name
:
eth0
address
:
"
3.0.0.3"
netmask
:
"
255.255.255.0"
gateway
:
"
3.0.0.2"
tasks
:
# - name: "Debug interfaces"
# ansible.builtin.debug:
# msg: "{{ item.name }}"
# loop: "{{ gns3_hosts[inventory_hostname].interfaces }}"
# - name: "Debug routes"
# ansible.builtin.debug:
# msg: "{{ item.network }}"
# loop: "{{ gns3_hosts[inventory_hostname].routes }}"
routes
:
R1
:
-
network
:
"
3.0.0.0/24"
via
:
"
2.0.0.2"
# - name: "Debug YAML"
# ansible.builtin.debug:
# msg: "{{ item.interfaces }}"
# loop: "{{ gns3_hosts[inventory_hostname] | dict2items }}"
# tags: debug_yaml
R2
:
-
network
:
"
1.0.0.0/24"
via
:
"
2.0.0.1"
-
name
:
"
Ensure
/etc/network/interfaces.d
exists"
tasks
:
-
name
:
Ensure /etc/network/interfaces.d exists
ansible.builtin.file
:
path
:
/etc/network/interfaces.d
state
:
directory
mode
:
'
0755'
-
name
:
"
Configure
network
interfaces
"
-
name
:
Configure network interfaces
ansible.builtin.template
:
src
:
"
./
templates/
interfaces
.j2"
dest
:
"
/etc/network/interfaces.d/{{
i
tem.
name
}}"
src
:
"
templates/
netconfig
.j2"
dest
:
"
/etc/network/interfaces.d/{{
i
nventory_host
name
}}"
owner
:
"
root"
group
:
"
root"
mode
:
"
0644"
loop
:
"
{{
gns3_hosts[inventory_hostname].interfaces
}}"
notify
:
Restart networking
-
name
:
"
Configure
routes"
ansible.builtin.template
:
src
:
"
./templates/routes.j2"
dest
:
"
/etc/network/interfaces.d/{{
inventory_hostname
}}_routes"
owner
:
"
root"
group
:
"
root"
mode
:
"
0644"
loop
:
"
{{
gns3_hosts[inventory_hostname].routes
}}"
when
:
inventory_hostname != "H1" and inventory_hostname != "H2"
notify
:
Restart networking
# - name: Verify H1 can ping H2
# command: ping -c 3 3.0.0.3
# - name: H1 pings H2
# ansible.builtin.command: ping -c 3 3.0.0.3
# register: ping_result
# changed_when: false
# failed_when: ping_result.rc != 0
# when: inventory_hostname == "H1"
#
# - name: H2 pings H2
# ansible.builtin.command: ping -c 3 1.0.0.3
# register: ping_result
# changed_when: false
# failed_when: ping_result.rc != 0
# when: inventory_hostname == "H2"
handlers
:
-
name
:
"
Restart
networking
"
-
name
:
Restart networking
ansible.builtin.systemd
:
name
:
networking
state
:
restarted
...
...
This diff is collapsed.
Click to expand it.
playbooks/templates/netconfig.j2
0 → 100644
+
17
−
0
View file @
03f42019
{% for intf in interfaces[inventory_hostname] %}
auto {{ intf.name }}
iface {{ intf.name }} inet static
address {{ intf.address }}
netmask {{ intf.netmask }}
{% if intf.gateway is defined %}
gateway {{ intf.gateway }}
{% endif %}
{% endfor %}
{% if inventory_hostname in routes %}
{% for route in routes[inventory_hostname] %}
post-up ip route add {{ route.network }} via {{ route.via }}
pre-down ip route del {{ route.network }} via {{ route.via }}
{% endfor %}
{% endif %}
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