-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelnet.yml
74 lines (54 loc) · 1.92 KB
/
telnet.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
---
- name: Configure new EVE-NG router
hosts: new_devices
connection: local
gather_facts: no
tasks:
- shell: |
spawn telnet 172.28.43.252 {{ansible_port}}
expect "Would you like to enter the initial configuration dialog? \[yes/no\]:"
send "no\n"
set send_human {.4 .4 .2 .5 100}
send -h "\r"
send -h "\r"
send -h "\r"
expect "Router>"
send "en\n"
expect "Router#"
send "conf t\n"
expect "Router(config)#"
send "no service config\n"
expect "Router(config)#"
send "hostname {{inventory_hostname}}\n"
expect "{{inventory_hostname}}(config)"
send "aaa new-model\n"
expect "{{inventory_hostname}}(config)"
send "ip domain-name .local\n"
expect "{{inventory_hostname}}(config)"
send "crypto key gen rsa mod 2048\n"
expect "1.99 has been enabled"
send "line vty 0 4\n"
expect "{{inventory_hostname}}(config-line)"
send "trans in ssh\n"
expect "{{inventory_hostname}}(config-line)"
send "exit\n"
expect "{{inventory_hostname}}(config)"
send "username kbreit pass cisco\n"
expect "{{inventory_hostname}}(config)"
send "enable pass cisco\n"
expect "{{inventory_hostname}}(config)"
send "do wr me\n"
expect "{{inventory_hostname}}(config)"
send "do sh ip int br e0/0\n"
expect "ethernet0"
args:
executable: /usr/bin/expect
changed_when: yes
delegate_to: localhost
register: expect_output
- debug:
msg: '{{expect_output}}'
- set_fact:
ip_add: '{{expect_output.stdout | regex_findall("(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)") | reject("search", "255.255.255.255") | list | last}}'
- debug:
msg: '{{ip_add}}'