Hi,

I would like to thank for telnet playbook that you provided. I am able to 
run show inventory command but for show run command, I am running with term 
len 0 and it does not store any output from show run.

cat vic-7yar-es-06-18.txt
terminal length 0

below is my playbook- 

- name: show version
  hosts: vic-7yar-es-06-18
  gather_facts: false
  connection: local
  tasks:
    - name: telnet sw
      telnet:
        user: 
        password: 
        login_prompt: "Username: "
        prompts:
          - '[>|#]'
        ios_command:
          - terminal length 0
          - show version

      register: output

    - debug: var=output

    - local_action: copy content="{{ output.output[0] }}" 
dest="device_backups/{{ inventory_hostname }}.txt"
On Wednesday, February 28, 2018 at 1:14:32 AM UTC+11 [email protected] wrote:

> Also, make sure your playbook is in proper YAML (I suspect your directory 
> does exist as you would get an explicit error for that if it did not)
>
> ---
> - hosts: cisco 
>   connection: local
>   gather_facts: False
>   ignore_errors: yes
> On Tue, Feb 27, 2018 at 5:42 AM, Claudia de Luna <[email protected]> wrote:
>
>> Hi,
>>
>> I mentioned this before. Are you certain this is the correct path 
>> "./etc...."
>>
>> This means that relative to where you are running your playbook you nave 
>> a directory called etc/ansible/backup/
>>
>> if you are trying to save your backup files to /etc/ansible/backup 
>> (absolute path) then you do not need the ".".
>>
>> and you must make sure that directory exists.
>>
>>  local_action: copy content="{{ output.output[0] }}" 
>> dest="*./etc/ansible/backup/{{ 
>> inventory_hostname }}.*txt"
>>
>
>> On Tue, Feb 27, 2018 at 3:26 AM, 'Daley Okuwa' via Ansible Project <
>> [email protected]> wrote:
>>
>>> Thanks
>>> but still getting errors 
>>>
>>> this is my code
>>>
>>> ---
>>>   hosts: cisco 
>>>   connection: local
>>>   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.output
>>>       - local_action: copy content="{{ output.output[0] }}" 
>>> dest="./etc/ansible/backup/{{ inventory_hostname }}.txt"
>>> and my errors message
>>>
>>> ansible@ansible-new:/etc/ansible$ ansible-playbook -i hosts 
>>> backup-cisconew.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
>>> ERROR! Syntax Error while loading YAML.
>>>
>>> The error appears to have been in '/etc/ansible/backup-cisconew.yml': 
>>> line 3, column 1, but may
>>> be elsewhere in the file depending on the exact syntax problem.
>>> The offending line appears to be:
>>>   hosts: cisco
>>>   connection: local
>>> ^ here
>>> exception type: <class 'yaml.parser.ParserError'>
>>> exception: did not find expected <document start>
>>>   in "<unicode string>", line 3, column 
>>>
>>> and also my hosts file
>>>
>>> ansible@ansible-new:/etc/ansible$ more hosts
>>> ##[all:vars]
>>> ##ansible_python_interpreter=/usr/bin/python
>>> ##ansible_connection=local
>>> [local]
>>> #localhost
>>> [cisco]
>>> 10.101.250.12 port=22 username=admin password=xxxxxx#
>>> 10.101.250.12 username=admin password=xxxxxx#
>>>
>>> ##[cisco:vars]
>>> ##device_type=cisco_ios
>>> ##username=ansible
>>> ##password=test123
>>>
>>>
>>>
>>>
>>> On Monday, February 26, 2018 at 5:18:55 PM UTC, Claudia de Luna wrote:
>>>
>>>> As Kai Stian Olstad mentioned, spacing is very important.
>>>>
>>>> Use a good text editor to make sure everything lines up.  Below is the 
>>>> playbook using Sublime.  Note the subtle lines to help you make sure 
>>>> everything lines up.
>>>>
>>>>
>>>>
>>>> [image: Inline image 1]
>>>>
>>>>
>>>>
>>>> On Mon, Feb 26, 2018 at 9:13 AM, Kai Stian Olstad <
>>>> [email protected]> wrote:
>>>>
>>>>> On Monday, 26 February 2018 18.03.30 CET 'Daley Okuwa' via Ansible 
>>>>> Project wrote:
>>>>> > ansible@ansible-new:/etc/ansible$ vi
>>>>> > backup_config-cisco12.yml                    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:
>>>>> >           module: copy
>>>>> >           content: "{{ output.output[0] }}"
>>>>> >           dest: "./etc/ansible/backup{{ inventory_hostname }}.txt"
>>>>>
>>>>> The "- local_action" line is indented one space to much.
>>>>> In YAML indentation is very impotent and it need to be consistent.
>>>>>
>>>>>
>>>>> --
>>>>> Kai Stian Olstad
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to a topic in the 
>>>>> Google Groups "Ansible Project" group.
>>>>> To unsubscribe from this topic, visit 
>>>>> https://groups.google.com/d/topic/ansible-project/jQqwdz51W3c/unsubscribe
>>>>> .
>>>>> To unsubscribe from this group and all its topics, 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/1955326.FrOzU2q6WV%40x1
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "Ansible Project" group.
>>> To unsubscribe from this topic, visit 
>>> https://groups.google.com/d/topic/ansible-project/jQqwdz51W3c/unsubscribe
>>> .
>>> To unsubscribe from this group and all its topics, 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/a54d9b9b-d657-4ee1-9626-ee01419da93a%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/ansible-project/a54d9b9b-d657-4ee1-9626-ee01419da93a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/df3b2ace-4bc1-4500-9304-22ce005029ccn%40googlegroups.com.

Reply via email to