[ansible-project] How to copy image files to IOS-XR device ?

2020-03-04 Thread 'Mysimpia' via Ansible Project
Hi, there;

In order to upgrade IOS-XR software, I need to copy IOS-XR image files to 
IOS-XR device. I was able to do it using scp from a Linux server CLI. 

However, I'd like to do it using Ansible playbook.  Already tried net_put 
and copy module but no luck. Has anyone been able to make it work 
successfully ? Would appreciate if the know how is shared.

Retrieving info using gather_facts or iosxr_commands works fine.

Here are my environment;

Ansible: 2.9.4
IOS-XR  Version  : 7.2.1.21I
Python version: 3.6.8


Thanks,

Joon.

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/955496b3-6f17-4eae-8955-5b2e6a6454cf%40googlegroups.com.


[ansible-project] Re: Ansible ios_command: copy tftp: flash: keeps sending IOS file data until timeout

2020-01-14 Thread 'Mysimpia' via Ansible Project

Ansible version : 2.9
Python version : 3.7.5

I also tried many times with sftp or scp with ios_command module but no 
luck. Instead, as shown below, net_put successfully copied the file over to 
the Cisco switch. The ansible_ssh_user and ansible_ssh_pass needs to be set 
in inventory file. 

One issue I'm facing with the net_put module is that next task using 
ios_command after the copying fails to be executed. It gave error message 
"ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)".
 
- name: Upgrade NM switch Firmware
  hosts: nm_switch
  connection: network_cli
  remote_user: cisco

- name: Copy over ios image
  net_put:
src: "{{ nm_sw_image_file }}" # Need ansible_ssh_user and 
ansible_ssh_pass set up.
  vars:
ansible_command_timeout: 3600 # default time out is 30 sec. Image copy 
takes about 30 min


On Sunday, June 16, 2019 at 11:02:24 AM UTC-4, Frankie Soto wrote:
>
> Hi!
>
> I am trying to automate the process of upgrading IOS on Cisco devices.
>
> Everything seems to be working fine until the process of copying the file 
> begins.
>
> The issue I am encountering is that ansible keeps sending data (I assume 
> it keeps sending the same file a couple of times in a stream) to the IOS 
> device.
>
> I noticed this issue when I logged in to one of the switches to which I am 
> trying to upgrade and saw how the file keeps growing and growing, to up to 
> four times its size (i.e. filesize is ~ 21k but it was growing already on 
> th 80k+).
>
> Process ends when the "timeout" time is reached.  Subsequently, the file 
> gets deleted from the switch, as the switches interprets that the file 
> transfer was interrupted.
>
>
> Here is y core.  Any help will be much appreciated:
>
> ---
> - hosts: [HOSTS]
>   gather_facts: yes
>   connection: local
>
>   vars:
> compliant_ios_version: 15.2(4)E8
> new_ios_bin: c3560cx-universalk9-mz.152-4.E8.bin
> new_ios_md5: bf2f1960b1fe0a05bdc69e17d82fcfed
> should_reboot: YES
>
>   vars_prompt:
>   - name: username
> prompt: "Enter username: "
> private: no
>
>   - name: password
> prompt: "Enter password: "
> private: yes
>
>   - name: auth_pass
> prompt: "Enter enable secret: "
> private: yes
>
>   tasks:
>
>   - name: gathering HOSTS facts
> ios_facts:
>   username: "{{ username }}"
>   password: "{{ password }}"
>   authorize: yes
>   auth_pass: "{{ auth_pass }}"
>   timeout: 30
> register: all_facts
>
>   - name:  Verifying if file exists in flash
> ios_command:
>   commands:
> - command: dir | include "{{ new_ios_bin }}"
>   username: "{{ username }}"
>   password: "{{ password }}"
>   authorize: yes
>   auth_pass: "{{ auth_pass }}"
>   timeout: 30
> register: new_ios_on_flash
>
>   - name:  Debugging new_ios_on_flash
> debug:
>   msg: new ios is flash is "{{ new_ios_on_flash }}"
>
>   - name: Starting IOS upgrade process
> block:
>
> - name: Upgrade IOS images if not compliant
>   block:
>   - name:  Download new IOS image if it is not already on flash
> ios_command:
>   commands:
> - command: 'copy tftp://
> 55.44.246.96/c3560cx-universalk9-mz.152-4.E8.bin flash:'
>   prompt: 'c3560cx-universalk9-mz.152-4.E8.bin'
>   answer: "\r"
>   username: "{{ username }}"
>   password: "{{ password }}"
>   authorize: yes
>   auth_pass: "{{ auth_pass }}"
>   timeout: 600
>   when: new_ios_on_flash.stdout[0] == ""
>
> - name: Checking MD5 hash
>   ios_command:
> commands:
> - command: "verify /md5 flash:/{{ new_ios_bin }}"
> username: "{{ username }}"
> password: "{{ password }}"
> authorize: yes
> auth_pass: "{{ auth_pass }}"
> timeout: 3000
>   register: md5_result
>
> - name:  Set boot var if MD5 matches
>   block:
>   - name:  Changing boot var
> ios_config:
>   lines:
> - default boot system
> - boot system flash:/"{{ new_ios_bin }}"
>   username: "{{ username }}"
>   password: "{{ password }}"
>   authorize: yes
>   auth_pass: "{{ auth_pass }}"
>   save_when: always
>   timeout: 150
> register: new_ios_on_flash
>
>   - name:  Setting boot var
> ios_command:
>   commands:
>   - command: "reload at 23:00\ny"
>   username: "{{ username }}"
>   password: "{{ password }}"
>   authorize: yes
>   auth_pass: "{{ auth_pass }}"
>   timeout: 30
>
>   when: md5_result.stdout[0][-32:] == new_ios_md5
>
> when: ansible_net_version != compliant_ios_version
>
>

-- 
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