From af4d72c38ebb93d0847da5116e9b52ffc5b08c98 Mon Sep 17 00:00:00 2001 From: bmzsombi <bmzsombi@sch.bme.hu> Date: Thu, 25 May 2023 15:26:40 +0200 Subject: [PATCH] playbook extended v2 --- maskrecover.py | 20 ++++++++++++++------ plays/test.yaml | 18 ++++++++++++++---- router1/router1_interface.txt | 10 ++++++++++ router1/router1_ip.txt | 6 ++++++ router1/router1_mask.txt | 6 ++++++ sort.sh | 2 ++ 6 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 router1/router1_interface.txt diff --git a/maskrecover.py b/maskrecover.py index d75c0aa..b4d7b00 100755 --- a/maskrecover.py +++ b/maskrecover.py @@ -1,11 +1,19 @@ def read_file(): - ip_path = "router1_ip.txt" - mask_path = "router1_mask.txt" + router1_ip_path = "router1/router1_ip.txt" + router1_mask_path = "router1/router1_mask.txt" + router2_ip_path = "router2/router2_ip.txt" + router2_mask_path = "router2/router2_mask.txt" - with open(ip_path, "r") as file: - lines = file.readlines() - for line in lines: - print(line.strip()) + with open(router1_ip_path, "r") as file: + router1_ips = file.readlines() + with open(router1_mask_path, "r") as file: + router1_masks = file.readlines() + with open(router2_ip_path, "r") as file: + router2_ips = file.readlines() + with open(router2_mask_path, "r") as file: + router2_masks = file.readlines() + if router1_masks < router2_masks: + router1_masks[0] = router2_masks[0] if __name__ == "__main__": diff --git a/plays/test.yaml b/plays/test.yaml index 2fe522a..1f23be6 100644 --- a/plays/test.yaml +++ b/plays/test.yaml @@ -4,12 +4,22 @@ gather_facts: no connection: network_cli tasks: - - name: Show int info + - name: Show static ruting table cisco.ios.ios_command: commands: show ip static route - register: interfaces_info + register: routing_table - - name: Print output + - name: Print routing table copy: - content: "{{interfaces_info.stdout[0]}}" + content: "{{routing_table.stdout[0]}}" dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}.txt + + - name: Show config of interfaces gi0/1 + cisco.ios.ios_command: + commands: show running-config interface gigabitEthernet 0/1 + register: interface_config + + - name: Print interface config + copy: + content: "{{interface_config.stdout[0]}}" + dest: ~/onlab/{{inventory_hostname}}/{{inventory_hostname}}_interface.txt diff --git a/router1/router1_interface.txt b/router1/router1_interface.txt new file mode 100644 index 0000000..6065c88 --- /dev/null +++ b/router1/router1_interface.txt @@ -0,0 +1,10 @@ +Building configuration... + +Current configuration : 119 bytes +! +interface GigabitEthernet0/1 + ip address 10.10.20.169 255.255.255.248 + duplex auto + speed auto + media-type rj45 +end \ No newline at end of file diff --git a/router1/router1_ip.txt b/router1/router1_ip.txt index 382cf6a..8c0e09b 100644 --- a/router1/router1_ip.txt +++ b/router1/router1_ip.txt @@ -1,2 +1,8 @@ 10.10.20.160 10.10.20.176 +10.10.20.160 +10.10.20.176 +10.10.20.160 +10.10.20.176 +10.10.20.160 +10.10.20.176 diff --git a/router1/router1_mask.txt b/router1/router1_mask.txt index bae7f4f..7fd56bc 100644 --- a/router1/router1_mask.txt +++ b/router1/router1_mask.txt @@ -1,2 +1,8 @@ 29 29 +29 +29 +29 +29 +29 +29 diff --git a/sort.sh b/sort.sh index 8cc53c7..9a6d5bd 100755 --- a/sort.sh +++ b/sort.sh @@ -1,2 +1,4 @@ cat ./router1/router1.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f1 >> ./router1/router1_ip.txt cat ./router1/router1.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f2 >> ./router1/router1_mask.txt +cat ./router2/router2.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f1 >> ./router2/router2_ip.txt +cat ./router2/router2.txt | grep "^M" | cut -d' ' -f3 | cut -d'/' -f2 >> ./router2/router2_mask.txt -- GitLab