From c199e80d5c7dd1c13d4dc9e1b80807c86d5dca52 Mon Sep 17 00:00:00 2001 From: goffinet Date: Sat, 19 Nov 2022 12:08:25 +0100 Subject: [PATCH] ossec lab update --- .../custom/osseclab/host_vars/controller | 7 +++++ inventories/custom/osseclab/host_vars/pc1 | 1 + inventories/custom/osseclab/host_vars/pc2 | 1 + inventories/custom/osseclab/host_vars/srv1 | 1 + inventories/custom/osseclab/host_vars/srv2 | 1 + .../osseclab/templates/controller_config.j2 | 11 ++++++-- playbooks/lab_setup.yml | 28 +++++++++---------- 7 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 inventories/custom/osseclab/host_vars/controller diff --git a/inventories/custom/osseclab/host_vars/controller b/inventories/custom/osseclab/host_vars/controller new file mode 100644 index 0000000..dd77ad0 --- /dev/null +++ b/inventories/custom/osseclab/host_vars/controller @@ -0,0 +1,7 @@ +--- +hostname: srv1 +interfaces: + - id: "System eth0" + ipv4_address: "11.12.13.1/24" + ipv4_dns: "11.12.13.1" +login_prompt: "localhost login:" diff --git a/inventories/custom/osseclab/host_vars/pc1 b/inventories/custom/osseclab/host_vars/pc1 index 7f84dbf..f329c32 100644 --- a/inventories/custom/osseclab/host_vars/pc1 +++ b/inventories/custom/osseclab/host_vars/pc1 @@ -2,3 +2,4 @@ hostname: pc1 interfaces: - id: "System eth0" +login_prompt: "localhost login:" diff --git a/inventories/custom/osseclab/host_vars/pc2 b/inventories/custom/osseclab/host_vars/pc2 index 6e919f5..9b3985e 100644 --- a/inventories/custom/osseclab/host_vars/pc2 +++ b/inventories/custom/osseclab/host_vars/pc2 @@ -2,3 +2,4 @@ hostname: pc2 interfaces: - id: "System eth0" +login_prompt: "localhost login:" diff --git a/inventories/custom/osseclab/host_vars/srv1 b/inventories/custom/osseclab/host_vars/srv1 index 15726d1..b776590 100644 --- a/inventories/custom/osseclab/host_vars/srv1 +++ b/inventories/custom/osseclab/host_vars/srv1 @@ -7,3 +7,4 @@ interfaces: ipv4_dns: "192.168.1.1" # ipv6_address: "2001:db8:acad:1060::50/64" # ipv6_gateway: "fe80::d1:3" +login_prompt: "localhost login:" diff --git a/inventories/custom/osseclab/host_vars/srv2 b/inventories/custom/osseclab/host_vars/srv2 index e25f9dd..81a7efb 100644 --- a/inventories/custom/osseclab/host_vars/srv2 +++ b/inventories/custom/osseclab/host_vars/srv2 @@ -7,3 +7,4 @@ interfaces: ipv4_dns: "192.168.1.1" # ipv6_address: "2001:db8:acad:3085::50/64" # ipv6_gateway: "fe80::3:3" +login_prompt: "localhost login:" diff --git a/inventories/custom/osseclab/templates/controller_config.j2 b/inventories/custom/osseclab/templates/controller_config.j2 index 0af9bd2..42e2d03 100644 --- a/inventories/custom/osseclab/templates/controller_config.j2 +++ b/inventories/custom/osseclab/templates/controller_config.j2 @@ -3,6 +3,11 @@ systemd-machine-id-setup hostnamectl set-hostname controller echo controller > /etc/hostname echo "" > /etc/motd -curl -s https://raw.githubusercontent.com/goffinet/ansible-ccna-lab/master/tests/setup-controller.sh -o setup.sh -bash setup.sh & -disown %1 +echo "curl -s https://raw.githubusercontent.com/goffinet/ansible-ccna-lab/master/tests/setup-controller.sh -o setup.sh" > readme.txt +echo "bash setup.sh ; reboot" >> readme.txt +{% 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 %} +#disown %1 diff --git a/playbooks/lab_setup.yml b/playbooks/lab_setup.yml index a54d4fe..72e7b61 100644 --- a/playbooks/lab_setup.yml +++ b/playbooks/lab_setup.yml @@ -120,20 +120,6 @@ post_login: 120 login_prompt: 60 config_dialog: 60 - - name: "Push config on centos nodes" - when: image_style == "centos" - telnet: - host: "{{ nodes_inventory[inventory_hostname]['server'] }}" - port: "{{ nodes_inventory[inventory_hostname]['console_port'] }}" - login_prompt: "localhost login:" - user: "{{ ansible_user }}" - password: "{{ ansible_password }}" - send_newline: yes - prompts: - - "[#]" - command: "{{ boilerplate_config.splitlines() }}" - timeout: 180 - pause: 2 - name: "Push config on openwrt nodes" when: image_style == "openwrt" gns3_telnet_console: @@ -148,6 +134,20 @@ post_login: 60 login_prompt: 30 config_dialog: 30 + - name: "Push config on centos nodes" + when: image_style == "centos" + telnet: + host: "{{ nodes_inventory[inventory_hostname]['server'] }}" + port: "{{ nodes_inventory[inventory_hostname]['console_port'] }}" + login_prompt: "{{ login_prompt | default('localhost login:') }}" + user: "{{ ansible_user }}" + password: "{{ ansible_password }}" + send_newline: yes + prompts: + - "[#]" + command: "{{ boilerplate_config.splitlines() }}" + timeout: 30 + pause: 2 tags: - provision - name: "Pause for 5 minutes to build all nodes"