Thanks for your reply
it was very useful
but I am getting errors
ansible-playbook -i hosts backup_config-cisco12.yml -vvv
ansible-playbook 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path =
[u'/home/ansible/.ansible/plugins/modules',
u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0
20160609]
Using /etc/ansible/ansible.cfg as config file
Parsed /etc/ansible/hosts inventory source with ini plugin
PLAYBOOK: backup_config-cisco12.yml
********************************************
1 plays in backup_config-cisco12.yml
PLAY [cisco]
*******************************************************************
META: ran handlers
TASK [run show command via Telnet]
*********************************************
task path: /etc/ansible/backup_config-cisco12.yml:8
fatal: [10.101.250.12]: FAILED! => {
"changed": true,
"msg": "Telnet action failed: telnet connection closed",
"output": []
}
...ignoring
TASK [debug]
*******************************************************************
task path: /etc/ansible/backup_config-cisco12.yml:22
ok: [10.101.250.12] => {
"output": {
"changed": true,
"failed": true,
"msg": "Telnet action failed: telnet connection closed",
"output": []
}
}
TASK [copy]
********************************************************************
task path: /etc/ansible/backup_config-cisco12.yml:25
fatal: [10.101.250.12]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The
error was: list object has no element 0\n\nThe error appears to have been
in '/etc/ansible/backup_config-cisco12.yml': line 25, column 9, but may\nbe
elsewhere in the file depending on the exact syntax problem.\n\nThe
offending line appears to be:\n\n\n - local_action: copy content=\"{{
output.output[0] }}\" dest=\"./etc/ansible/backup{{ inventory_hostname
}}.txt\"\n ^ here\nWe could be wrong, but this one looks like it
might be an issue with\nmissing quotes. Always quote template expression
brackets when they\nstart a value. For instance:\n\n with_items:\n
- {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo
}}\"\n\nexception type: <class
'ansible.errors.AnsibleUndefinedVariable'>\nexception: list object has no
element 0"
}
...ignoring
META: ran handlers
META: ran handlers
PLAY RECAP
*********************************************************************
10.101.250.12 : ok=3 changed=1 unreachable=0 failed=0
This is the config below
---
- hosts: cisco
connection: local
gather_facts: False
ignore_errors: yes
tasks:
- name: run show command via Telnet
telnet:
user: "{{ username }}"
password: "{{ password }}"
login_prompt: "Username: "
prompts:
- "[>|#]"
command:
# - terminal length 0
# - show run
- show inventory
register: output
- debug: var=output
- local_action: copy content="{{ output.output[0] }}"
dest="./etc/ansible/backup{{ inventory_hostname }}.txt"
On Saturday, February 24, 2018 at 1:21:32 PM UTC, Claudia de Luna wrote:
> Hi,
>
> You can try using the new (as of Ansible 2.4) "preview" telnet module:
> telnet - Executes a low-down and dirty telnet command
> http://docs.ansible.com/ansible/2.4/telnet_module.html
>
> Make sure your host file entries resolve in DNS or just use the IP.
>
> Sample host file group:
>
>
> [cisco]
> arctic-sw01 host=10.1.10.100 port=22 username=cisco password=cisco
> 10.1.10.100 username=cisco password=cisco
>
> Sample Playbook - here I am just getting the show inventory output
> (because its short) and saving it to a variable called output with is a
> data structure of all the output. Then I take the part I want to save, the
> actual show inventory output and save it to a file called <hostname>.txt in
> the ./FACTs directory.
> You can uncomment the term len 0 and show run commands and do the same.
> ---
> - hosts: cisco
> connection: local
> gather_facts: False
> ignore_errors: yes
>
> tasks:
> - name: run show commands via Telnet
> telnet:
> user: "{{ username }}"
> password: "{{ password }}"
> login_prompt: "Username: "
> prompts:
> - "[>|#]"
> command:
> # - terminal length 0
> # - show run
> - show inventory
>
> register: output
>
> - debug: var=output
>
> - local_action: copy content="{{ output.output[0] }}" dest="./FACTs/{{
> inventory_hostname }}.txt"
>
>
>
> Sample Run:
> root@127c868b9dd3:/ansible/ansible2_4_base# ansible-playbook -i hosts
> ios_telnet.yml
>
> PLAY [cisco]
> ********************************************************************************************************************************
>
> TASK [run show commands via Telnet]
> *********************************************************************************************************
> changed: [arctic-sw01]
> changed: [10.1.10.100]
>
> TASK [debug]
> ********************************************************************************************************************************
> ok: [arctic-sw01] => {
> "output": {
> "changed": true,
> "failed": false,
> "output": [
> "show inventory\r\nNAME: \"arctic-sw01\", DESCR: \"Cisco
> Catalyst c2940 switch with 8 10/100 BaseTX ports and 1 10/100/1000 BaseT
> uplink port\"\r\nPID: WS-C2940-8TT-S , VID: D0 , SN:
> FHK0834Y19X\r\n\r\n\r\narctic-sw01#"
> ]
> }
> }
> ok: [10.1.10.100] => {
> "output": {
> "changed": true,
> "failed": false,
> "output": [
> "show inventory\r\nNAME: \"arctic-sw01\", DESCR: \"Cisco
> Catalyst c2940 switch with 8 10/100 BaseTX ports and 1 10/100/1000 BaseT
> uplink port\"\r\nPID: WS-C2940-8TT-S , VID: D0 , SN:
> FHK0834Y19X\r\n\r\n\r\narctic-sw01#"
> ]
> }
> }
>
> TASK [copy]
> *********************************************************************************************************************************
> changed: [arctic-sw01 -> localhost]
> changed: [10.1.10.100 -> localhost]
>
> PLAY RECAP
> **********************************************************************************************************************************
> 10.1.10.100 : ok=3 changed=2 unreachable=0 failed=0
> arctic-sw01 : ok=3 changed=2 unreachable=0 failed=0
>
> root@127c868b9dd3:/ansible/ansible2_4_base# cd facts/
> root@127c868b9dd3:/ansible/ansible2_4_base/facts# ls
> 10.1.10.100.txt arctic-sw01.txt nxos-spine1.txt nxos-spine2.txt
> root@127c868b9dd3:/ansible/ansible2_4_base/facts# cat 10.1.10.100.txt
> show inventory
> NAME: "arctic-sw01", DESCR: "Cisco Catalyst c2940 switch with 8 10/100
> BaseTX ports and 1 10/100/1000 BaseT uplink port"
> PID: WS-C2940-8TT-S , VID: D0 , SN: FHK0834Y19X
>
>
> arctic-sw01#root@127c868b9dd3:/ansible/ansible2_4_base/facts
>
>
> Hope this helps.
>
> The only other approach I'm aware of is to use the NTC modules which use
> Napalm and the Cisco IOS modules use Netmiko under the hood which supports
> Telnet although last I checked I didn't think the Telnet option was
> exposed.
>
> Note that the end goal of this module is to telnet to a device to enable
> SSH but I know that is sometimes not possible.
>
>
>
>
>
>
> On Thursday, February 22, 2018 at 6:08:11 AM UTC-8, Daley Okuwa wrote:
>>
>> Is there any information that allows me to backup a cisco device using
>> telnet rather than ssh as the device do not support SSH
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d1b5e470-5329-46de-8881-2fdf9f42d9ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.