Skip to content

Commit f29320c

Browse files
committed
added a playbook template for CML console connections and accompanying inventory
1 parent be01c14 commit f29320c

8 files changed

Lines changed: 115 additions & 3 deletions

File tree

‎ansible.cfg‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
[defaults]
22
root = ~/projects/netdevops/
33
inventory = ./inventory
4-
stdout_callback = json
4+
stdout_callback = default
5+
callback_result_format = yaml
56
result_format = yaml
67
forks = 10
78
timeout = 30
89
gathering = explicit
910
retry_files_enabled = False
1011
host_key_checking = False
11-
deprecation_warnings = True
12+
deprecation_warnings = False
1213
log_path = ./logs/ansible.log
1314

1415
[persistent_connection]

‎inventory/consoles.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
all:
2+
children:
3+
consoles:
4+
vars:
5+
ansible_connection: local
6+
ansible_host: localhost
7+
telnet_user: "{{ lookup('env', 'CISCO_USER') }}"
8+
telnet_password: "{{ lookup('env', 'CISCO_PASS') }}"
9+
hosts:
10+
r1:
11+
telnet_port: 9001
12+
r2:
13+
telnet_port: 9002
14+
r3:
15+
telnet_port: 9003
16+
r4:
17+
telnet_port: 9004
18+
r5:
19+
telnet_port: 9005
20+
r6:
21+
telnet_port: 9006

‎inventory/group_vars/consoles.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ansible_connection: ansible.netcommon.network_cli
2+
ansible_network_os: cisco.ios.ios
3+
4+
ansible_user: "{{ lookup('env', 'CISCO_USER') }}"
5+
ansible_password: "{{ lookup('env', 'CISCO_PASS') }}"
6+
7+
ansible_command_timeout: 60
8+
ansible_connect_timeout: 60

‎inventory/lab.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,22 @@ all:
3030
hosts:
3131
sp1:
3232
ansible_host: 10.0.0.248
33+
consoles:
34+
vars:
35+
ansible_connection: local
36+
ansible_host: localhost
37+
telnet_user: "{{ lookup('env', 'CISCO_USER') }}"
38+
telnet_password: "{{ lookup('env', 'CISCO_PASS') }}"
39+
hosts:
40+
r1:
41+
telnet_port: 9001
42+
r2:
43+
telnet_port: 9002
44+
r3:
45+
telnet_port: 9003
46+
r4:
47+
telnet_port: 9004
48+
r5:
49+
telnet_port: 9005
50+
r6:
51+
telnet_port: 9006

‎playbooks/consoles_pb.yml‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
- name: CML console playbook
2+
hosts: consoles
3+
gather_facts: false
4+
5+
tasks:
6+
- name: Run commands through an existing or new console session
7+
ansible.builtin.expect:
8+
command: "telnet {{ ansible_host }} {{ telnet_port }}"
9+
timeout: 10
10+
echo: false
11+
responses:
12+
"(?i)Escape character is \\'\\^\\]\\'\\.\\s*$": "\r"
13+
14+
'(?i)Username:\s*$': "{{ telnet_user }}"
15+
'(?i)Password:\s*$': "{{ telnet_password }}"
16+
17+
# Exit the local Telnet client cleanly.
18+
'(?i)telnet>\s*$': "quit"
19+
20+
"(?i)Press RETURN to get started\\.": "\u001d"
21+
22+
# Each successive IOS prompt sends the next response.
23+
'(?m)^(?!telnet>)[^\r\n]*[>#]\s*$':
24+
- "terminal length 0"
25+
- "show clock"
26+
- "show version | include uptime"
27+
- "show ip interface brief"
28+
# - "exit\r\n\u001dquit\r"
29+
- "exit"
30+
- "\u001d"
31+
register: out
32+
changed_when: false
33+
delegate_to: localhost
34+
vars:
35+
ansible_python_interpreter: "{{ ansible_playbook_python }}"
36+
37+
- name: Results
38+
ansible.builtin.debug:
39+
msg: "{{ out.stdout | replace('\\'', '') }}"

‎playbooks/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- hosts: default
2+
- hosts: consoles
33
gather_facts: no
44

55
tasks:

‎pyproject.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ dependencies = [
88
"ansible>=11.9.0",
99
"ansible-pylibssh>=1.2.2",
1010
"paramiko>=4.0.0",
11+
"pexpect>=4.9.0",
1112
"pyats[full]>=25.7",
1213
"python-dotenv>=1.1.1",
1314
]

‎uv.lock‎

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)