Posted on April 26, 2019 6:53 pm
 |  Asked by Nilesh Bhadane
 |  216 views
0
0
Print Friendly, PDF & Email

HI,

Is it possible to write an ansible script to push file from my machine to arista device?

Thanks,
Nilesh

0
Posted by Kishore Sukumaran
Answered on May 29, 2019 5:53 pm

Hello Nilesh,

So, this is possible but you would need to have a bash shell to create a user:

$ username ansible secret ansible privilege 15 shell /bin/bash

You can then use the ‘copy’ module (https://docs.ansible.com/ansible/2.4/copy_module.html) to achieve this. Just edit your playbook, inventory and vars at that point like it is another linux device.

– name: copy over files.

copy:

src: “{{ item.src }}”

dest: “{{ item.dest }}”

mode: “{{ item.mode }}”

connection: ssh

remote_user: ansible

password: ansible

become: yes

with_items:

– { src: file1 , dest: /mnt/flash , mode: 0770}

– { src: file2 , dest: /mnt/flash , mode: 0770}

Hope this helped. Let me know if this worked for you.

Glad to help!

Kishore

0
Posted by Alexandru
Answered on May 29, 2019 7:45 pm

Hi Nilesh,

If Kishores suggestion doesn’t work in your environment you could also use the following playbook.
The requirements are the following:
1. User used by Ansible must be configured for SSH key authentication
2. User must go into privileged mode on login and not used enable

Playbook is here https://pastebin.com/raw/YTGntKg8 so the formatting is preserved.

Post your Answer

You must be logged in to post an answer.