Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
goffinet committed Dec 9, 2021
1 parent 5619824 commit 612d051
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 11 deletions.
141 changes: 141 additions & 0 deletions inventories/custom/biglan/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
---
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: "biglan"
gns3_nodes_spec:
- name: "management1"
template: "Ethernet switch"
x: -450
y: 250
- name: "management0"
template: "Ethernet switch"
x: 150
y: 250
- name: "management2"
template: "Ethernet switch"
x: 350
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: "lan1"
template: "Ethernet switch"
x: -200
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
- name: "pc5"
template: "linux-server"
x: -350
y: 100
- name: "pc6"
template: "linux-server"
x: -250
y: 100
- name: "lan2"
template: "Ethernet switch"
x: 200
y: -50
- name: "pc7"
template: "linux-server"
x: -150
y: 100
- name: "pc8"
template: "linux-server"
x: -50
y: 100
- name: "pc9"
template: "linux-server"
x: 50
y: 100
- name: "pc10"
template: "linux-server"
x: 150
y: 100
- name: "pc11"
template: "linux-server"
x: 250
y: 100
- name: "pc12"
template: "linux-server"
x: 350
y: 100
- name: "pc13"
template: "linux-server"
x: 350
y: 0
- name: "pc14"
template: "linux-server"
x: 350
y: -100
- name: "pc15"
template: "linux-server"
x: 350
y: -200
gns3_links_spec:
- ["lan0", "Ethernet0", "Internet", "nat0"]
- ["lan1", "Ethernet0", "lan0", "Ethernet1"]
- ["lan2", "Ethernet0", "lan0", "Ethernet2"]
- ["lan1", "Ethernet1", "pc1", "Ethernet0"]
- ["lan1", "Ethernet2", "pc2", "Ethernet0"]
- ["lan1", "Ethernet3", "pc3", "Ethernet0"]
- ["lan1", "Ethernet4", "pc4", "Ethernet0"]
- ["lan1", "Ethernet5", "pc5", "Ethernet0"]
- ["lan1", "Ethernet6", "pc6", "Ethernet0"]
- ["lan1", "Ethernet7", "pc7", "Ethernet0"]
- ["lan2", "Ethernet1", "pc8", "Ethernet0"]
- ["lan2", "Ethernet2", "pc9", "Ethernet0"]
- ["lan2", "Ethernet3", "pc10", "Ethernet0"]
- ["lan2", "Ethernet4", "pc11", "Ethernet0"]
- ["lan2", "Ethernet5", "pc12", "Ethernet0"]
- ["lan2", "Ethernet6", "pc13", "Ethernet0"]
- ["lan2", "Ethernet7", "pc14", "Ethernet0"]
- ["lan0", "Ethernet3", "pc15", "Ethernet0"]
- ["natctrl", "nat0", "controller", "Ethernet1"]
- ["management0", "Ethernet0", "controller", "Ethernet0"]
- ["management0", "Ethernet1", "management1", "Ethernet0"]
- ["management0", "Ethernet2", "management2", "Ethernet0"]
- ["management1", "Ethernet1", "pc1", "Ethernet1"]
- ["management1", "Ethernet2", "pc2", "Ethernet1"]
- ["management1", "Ethernet3", "pc3", "Ethernet1"]
- ["management1", "Ethernet4", "pc4", "Ethernet1"]
- ["management1", "Ethernet5", "pc5", "Ethernet1"]
- ["management1", "Ethernet6", "pc6", "Ethernet1"]
- ["management1", "Ethernet7", "pc7", "Ethernet1"]
- ["management2", "Ethernet1", "pc8", "Ethernet1"]
- ["management2", "Ethernet2", "pc9", "Ethernet1"]
- ["management2", "Ethernet3", "pc10", "Ethernet1"]
- ["management2", "Ethernet4", "pc11", "Ethernet1"]
- ["management2", "Ethernet5", "pc12", "Ethernet1"]
- ["management2", "Ethernet6", "pc13", "Ethernet1"]
- ["management2", "Ethernet7", "pc14", "Ethernet1"]
- ["management0", "Ethernet3", "pc15", "Ethernet1"]
4 changes: 4 additions & 0 deletions inventories/custom/biglan/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/biglan/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/biglan/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[controllers]
controller

[pcs]
pc[1:15]

[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/biglan/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/biglan/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/biglan/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
1 change: 0 additions & 1 deletion playbooks/lab_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
minutes: 5
tags:
- provision
- duplicate
- name: "Stop all nodes"
gns3_project:
url: "{{ gns3_url }}"
Expand Down
11 changes: 1 addition & 10 deletions tests/setup-controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ interface=eth0
dhcp-range=11.12.13.100,11.12.13.150,255.255.255.0,512h
dhcp-option=3
EOF
cat << EOF > /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
TYPE=Ethernet
IPADDR=11.12.13.1
PREFIX=24
IPV4_FAILURE_FATAL=no
DNS1=127.0.0.1
EOF
sed -i 's/^#\$ModLoad imudp/$ModLoad imudp/g' /etc/rsyslog.conf
sed -i 's/^#\$UDPServerRun 514/$UDPServerRun 514/g' /etc/rsyslog.conf
sed -i 's/^#\$ModLoad imtcp/$ModLoad imtcp/g' /etc/rsyslog.conf
Expand All @@ -35,6 +25,7 @@ firewall-cmd --permanent --add-service dhcp
firewall-cmd --permanent --add-service dns
firewall-cmd --permanent --add-service syslog
firewall-cmd --reload
systemctl start dnsmasq
yum -y install python3-pip sshpass python3-paramiko python3-netaddr python3-ansible-lint ansible git
git clone https://github.com/goffinet/ansible-ccna-lab
echo "end: $(date)" >> /root/setup.log

0 comments on commit 612d051

Please sign in to comment.