Skip to content

Instantly share code, notes, and snippets.

@gainskills
Last active July 11, 2020 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gainskills/20b6920d536a94de484ad073a06ef7d8 to your computer and use it in GitHub Desktop.
Save gainskills/20b6920d536a94de484ad073a06ef7d8 to your computer and use it in GitHub Desktop.
Sample about Ansible telnet
#telnet part1
ansible-playbook -i inventory_telnet.yml pb_telnet.yml
#Telnet Part2
ansible-playbook -i inventory_telnet.yml --vault-id test@prompt pb_telnet.yml
#SSH
ansible-playbook -i inventory_ssh.yml pb_first.yml
ansible-playbook -i inventory_ssh.yml --vault-id test@prompt pb_first.yml
---
telnet:
hosts:
sw1:
ansible_host: "192.168.1.100"
connection: local
ansible_ssh_user: test
ansible_ssh_pass: !vault |
$ANSIBLE_VAULT;1.2;AES256;test
63386332356237643731346539336262336231343432313963376438653933323737636535383365
3562383633646261653739343536386566323462323063320a613638373439363032353137343330
34306264613932323832373532636230323730626239393564326564303563356666343734633135
6664373266663238660a363666336661353364393437356433616462346331313537623430393861
3536
ansible_ssh_timeout: 2
ansible_ssh_port: 23
---
netconf:
hosts:
netconfIos:
ansible_host: "172.16.254.100"
ansible_network_os: "ios"
ansible_ssh_port: 22
netconfJunos:
ansible_host: "172.16.254.9"
ansible_network_os: "junos"
ansible_ssh_port: 830
vars:
ansible_connection: "netconf"
ansible_ssh_user: test
ansible_ssh_pass: test123
---
user:
hosts:
user_R:
ansible_host: "192.168.1.97"
vars:
ansible_network_os: "ios"
ansible_ssh_user: test
ansible_ssh_pass: test123
pubkeynopass:
hosts:
pubkeynopass_R:
ansible_host: "192.168.1.98"
vars:
ansible_network_os: "ios"
ansible_ssh_user: sshpubkey
ansible_ssh_private_key_file: '/Users/kz/Documents/SSH/tmp/id_rsa_nokey'
pubkeypass:
hosts:
pubkeypass_R:
ansible_host: "192.168.1.99"
vars:
ansible_network_os: "ios"
ansible_ssh_user: sshpubkeypass
ansible_ssh_private_key_file: /Users/kz/Documents/SSH/tmp/id_rsa_pass
ansible_ssh_pass: test123
---
telnet:
hosts:
sw1:
ansible_host: "192.168.1.100"
---
telnet:
hosts:
sw1:
ansible_host: "192.168.1.100"
connection: local
ansible_ssh_user: test
ansible_ssh_pass: test123
ansible_ssh_timeout: 2
ansible_ssh_port: 23
---
- name: show version
hosts: telnet
gather_facts: false
# connection: local
tasks:
- name: CM via telnet
telnet:
login_prompt: "Username: "
prompts:
- '[>|#]'
command:
- terminal length 0
- show version
---
- name: show version
hosts: telnet
gather_facts: false
# connection: local
tasks:
- name: CM via telnet
telnet:
login_prompt: "Username: "
prompts:
- '[>#]'
command:
- terminal length 0
- show version | include uptime
- show version | include Processor board ID
- exit
---
- name: ssh username/password
connection: network_cli
hosts: user
become_method: enable
tasks:
- name: Get config for IOS devices
ios_facts:
gather_subset: all
- name: Display the config
debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
- name: ssh username/keyWithoutPassword
connection: network_cli
hosts: pubkeynopass
become_method: enable
tasks:
- name: Get config for IOS devices
ios_facts:
gather_subset: all
- name: Display the config
debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
- name: ssh username/keyWithPassword
connection: network_cli
hosts: pubkeypass
become_method: enable
tasks:
- name: Get config for IOS devices
ios_facts:
gather_subset: all
- name: Display the config
debug:
msg: "The hostname is {{ ansible_net_hostname }} and the OS is {{ ansible_net_version }}"
---
- name: IOS
hosts: netconfIos
gather_facts: false
tasks:
- name: Get config for IOS devices
netconf_get:
source: running
register: iosnetconf
- name: Display output
debug:
msg: "{{ iosnetconf.stdout }}"
---
- name: show version
hosts: telnet
gather_facts: false
connection: local
tasks:
- name: telnet sw
telnet:
user: test
password: test123
login_prompt: "Username: "
prompts:
- '[>|#]'
command:
- terminal length 0
- show version
@azevedozero
Copy link

Hi Guys,

How i get the output from show version via Telnet?

Best Regards.

@gainskills
Copy link
Author

Hi Guys,

How i get the output from show version via Telnet?

Best Regards.

Please try to follow this: https://blog.gainskills.top/2018/09/04/ansible-access-network-via-telnet/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment