From 612d0517a231feee599831dc734ee35d70020808 Mon Sep 17 00:00:00 2001 From: goffinet Date: Thu, 9 Dec 2021 15:09:37 +0100 Subject: [PATCH] update --- inventories/custom/biglan/group_vars/all | 141 ++++++++++++++++++ inventories/custom/biglan/group_vars/pcs.yml | 4 + .../custom/biglan/host_vars/controller.yml | 6 + inventories/custom/biglan/hosts | 19 +++ .../biglan/templates/controller_config.j2 | 17 +++ .../custom/biglan/templates/default_config.j2 | 6 + .../custom/biglan/templates/pcs_config.j2 | 5 + playbooks/lab_setup.yml | 1 - tests/setup-controller.sh | 11 +- 9 files changed, 199 insertions(+), 11 deletions(-) create mode 100644 inventories/custom/biglan/group_vars/all create mode 100644 inventories/custom/biglan/group_vars/pcs.yml create mode 100644 inventories/custom/biglan/host_vars/controller.yml create mode 100644 inventories/custom/biglan/hosts create mode 100644 inventories/custom/biglan/templates/controller_config.j2 create mode 100644 inventories/custom/biglan/templates/default_config.j2 create mode 100644 inventories/custom/biglan/templates/pcs_config.j2 diff --git a/inventories/custom/biglan/group_vars/all b/inventories/custom/biglan/group_vars/all new file mode 100644 index 0000000..231eca4 --- /dev/null +++ b/inventories/custom/biglan/group_vars/all @@ -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"] diff --git a/inventories/custom/biglan/group_vars/pcs.yml b/inventories/custom/biglan/group_vars/pcs.yml new file mode 100644 index 0000000..ecb2d42 --- /dev/null +++ b/inventories/custom/biglan/group_vars/pcs.yml @@ -0,0 +1,4 @@ +--- +hostname: "{{ inventory_hostname }}" +interfaces: + - id: "System eth0" diff --git a/inventories/custom/biglan/host_vars/controller.yml b/inventories/custom/biglan/host_vars/controller.yml new file mode 100644 index 0000000..bf2fd38 --- /dev/null +++ b/inventories/custom/biglan/host_vars/controller.yml @@ -0,0 +1,6 @@ +--- +hostname: controller +interfaces: + - id: "System eth0" + ipv4_address: "11.12.13.1/24" + ipv4_dns: "127.0.0.1" diff --git a/inventories/custom/biglan/hosts b/inventories/custom/biglan/hosts new file mode 100644 index 0000000..b4a8cfa --- /dev/null +++ b/inventories/custom/biglan/hosts @@ -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 diff --git a/inventories/custom/biglan/templates/controller_config.j2 b/inventories/custom/biglan/templates/controller_config.j2 new file mode 100644 index 0000000..65cf0bb --- /dev/null +++ b/inventories/custom/biglan/templates/controller_config.j2 @@ -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 diff --git a/inventories/custom/biglan/templates/default_config.j2 b/inventories/custom/biglan/templates/default_config.j2 new file mode 100644 index 0000000..c0bc4ab --- /dev/null +++ b/inventories/custom/biglan/templates/default_config.j2 @@ -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 %} diff --git a/inventories/custom/biglan/templates/pcs_config.j2 b/inventories/custom/biglan/templates/pcs_config.j2 new file mode 100644 index 0000000..be71267 --- /dev/null +++ b/inventories/custom/biglan/templates/pcs_config.j2 @@ -0,0 +1,5 @@ +rm -f /etc/machine-id +systemd-machine-id-setup +hostnamectl set-hostname {{ hostname }} +echo {{ hostname }} > /etc/hostname +echo "" > /etc/motd diff --git a/playbooks/lab_setup.yml b/playbooks/lab_setup.yml index 1c5c2cd..a54d4fe 100644 --- a/playbooks/lab_setup.yml +++ b/playbooks/lab_setup.yml @@ -155,7 +155,6 @@ minutes: 5 tags: - provision - - duplicate - name: "Stop all nodes" gns3_project: url: "{{ gns3_url }}" diff --git a/tests/setup-controller.sh b/tests/setup-controller.sh index 5958ecf..3329df5 100644 --- a/tests/setup-controller.sh +++ b/tests/setup-controller.sh @@ -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 @@ -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