Skip to content

Commit

Permalink
add smalllan
Browse files Browse the repository at this point in the history
  • Loading branch information
goffinet committed Dec 16, 2021
1 parent 612d051 commit d043223
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
55 changes: 55 additions & 0 deletions inventories/custom/smalllan/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
template: "{{ inventory_dir }}/templates/default_config.j2"
gns3_url: "http://172.16.253.1"
gns3_lab_user: "{{ ansible_user }}"
gns3_lab_pass: "{{ ansible_ssh_pass }}"
project_name: "smalllan"
gns3_nodes_spec:
- name: "management0"
template: "Ethernet switch"
x: 150
y: 250
- name: "controller"
template: "controller"
x: 0
y: 300
- name: "natctrl"
template: "NAT"
x: -350
y: 300
- name: "Internet"
template: "NAT"
x: -50
y: -200
- name: "lan0"
template: "Ethernet switch"
x: 0
y: -50
- name: "pc1"
template: "linux-server"
x: -450
y: -200
- name: "pc2"
template: "linux-server"
x: -450
y: -100
- name: "pc3"
template: "linux-server"
x: -450
y: 0
- name: "pc4"
template: "linux-server"
x: -450
y: 100
gns3_links_spec:
- ["lan0", "Ethernet0", "Internet", "nat0"]
- ["lan0", "Ethernet1", "pc1", "Ethernet0"]
- ["lan0", "Ethernet2", "pc2", "Ethernet0"]
- ["lan0", "Ethernet3", "pc3", "Ethernet0"]
- ["lan0", "Ethernet4", "pc4", "Ethernet0"]
- ["natctrl", "nat0", "controller", "Ethernet1"]
- ["management0", "Ethernet0", "controller", "Ethernet0"]
- ["management0", "Ethernet1", "pc1", "Ethernet1"]
- ["management0", "Ethernet2", "pc2", "Ethernet1"]
- ["management0", "Ethernet3", "pc3", "Ethernet1"]
- ["management0", "Ethernet4", "pc4", "Ethernet1"]
4 changes: 4 additions & 0 deletions inventories/custom/smalllan/group_vars/pcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
hostname: "{{ inventory_hostname }}"
interfaces:
- id: "System eth0"
6 changes: 6 additions & 0 deletions inventories/custom/smalllan/host_vars/controller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
hostname: controller
interfaces:
- id: "System eth0"
ipv4_address: "11.12.13.1/24"
ipv4_dns: "127.0.0.1"
19 changes: 19 additions & 0 deletions inventories/custom/smalllan/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[controllers]
controller

[pcs]
pc[1:3]

[linux:children]
pcs
controllers

[linux:vars]
image_style=centos
ansible_network_os=""
ansible_connection=ssh

[all:vars]
ansible_user=root
ansible_ssh_pass=testtest
ansible_port=22
17 changes: 17 additions & 0 deletions inventories/custom/smalllan/templates/controller_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
rm -f /etc/machine-id
systemd-machine-id-setup
hostnamectl set-hostname {{ hostname }}
echo {{ hostname }} > /etc/hostname
{% for interface in interfaces %}
nmcli c mod "{{ interface['id'] }}" ipv4.method manual ipv4.addresses {{ interface['ipv4_address'] }}
nmcli c mod "{{ interface['id'] }}" ipv4.dns {{ interface['ipv4_dns'] }}
nmcli c up "{{ interface['id'] }}"
{% endfor %}
echo "" > /etc/motd
curl -s https://raw.githubusercontent.com/goffinet/ansible-ccna-lab/master/tests/setup-controller.sh -o setup.sh
chmod +x setup.sh
curl -s https://raw.githubusercontent.com/goffinet/ansible-ccna-lab/master/tests/setup.service -o /etc/systemd/system/setup.service
systemctl daemon-reload
systemctl enable setup.service
ln -s /etc/systemd/system/setup.service /etc/systemd/system/multi-user.target.wants/setup.service
systemctl start setup.service
6 changes: 6 additions & 0 deletions inventories/custom/smalllan/templates/default_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if inventory_hostname == "controller" and image_style == "centos" %}
{% include 'controller_config.j2' %}
{% endif %}
{% if inventory_hostname in groups['pcs'] and image_style == "centos" %}
{% include 'pcs_config.j2' %}
{% endif %}
5 changes: 5 additions & 0 deletions inventories/custom/smalllan/templates/pcs_config.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rm -f /etc/machine-id
systemd-machine-id-setup
hostnamectl set-hostname {{ hostname }}
echo {{ hostname }} > /etc/hostname
echo "" > /etc/motd

0 comments on commit d043223

Please sign in to comment.