# Unable to copy file from ansible server to Juniper Switch

**URL:** <https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079>\
**Category:** Get Help\
**Tags:** playbook, network\
**Created:** [November 1, 2023, 3:25pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079 "2023-11-01T15:25:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![G24joshi](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@G24joshi](https://forum.ansible.com/u/G24joshi)\
**Post date:** [November 1, 2023, 3:25pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/1 "2023-11-01T15:25:34Z")

</div>

Hi,

I am unable to copy file from ansible server to juniper switch, I am pasting my playbook, hosts file & group\_vars file below and the error which I am getting. Please have a look into this & help to resolve the issue.

Thanks in Advance.  
G24Joshi

## My Playbook:-

- hosts: juniperswitch  
gather\_facts: no  
vars:  
ansible\_command\_timeout: 1800  
connection: local

* * *

## Error:

The full traceback is:  
File “/root/.ansible/collections/ansible\_collections/junipernetworks/junos/plugins/modules/junos\_scp.py”, line 224, in main  
device = get\_device(module)  
File “/root/.ansible/collections/ansible\_collections/junipernetworks/junos/plugins/module\_utils/network/junos/junos.py”, line 155, in get\_device  
device = Device(host, \*\*kwargs)  
File “/usr/local/lib/python3.8/site-packages/jnpr/junos/device.py”, line 1263, in **init**  
raise ValueError(“You must provide either ‘host’ or ‘sock\_fd’ value”)  
fatal: [59.4.42.44]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“dest”: “/var/tmp/”,  
“provider”: {},  
“recursive”: false,  
“remote\_src”: false,  
“src”: [  
“testing6.txt”  
],  
“ssh\_config”: null,  
“ssh\_private\_key\_file”: null  
}  
},  
**“msg”: “You must provide either ‘host’ or ‘sock\_fd’ value”**  
}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
59.4.42.44 : ok=0 changed=0 unreachable=0 **failed=1** skipped=0 rescued=0 ignored=0

## Playbook run took 0 days, 0 hours, 0 minutes, 0 seconds

## My hosts file:

[root@lonans01 juniperymls]# cat /etc/ansible/hosts

[juniperswitch]  
59.4.42.44

## [root@lonans01 juniperymls]#

## My group\_vars file:-

## [root@lonans01 juniperymls]# cat /etc/ansible/group\_vars/juniperswitch ansible\_network\_os: junos ansible\_user: admin.ba ansible\_password: \*\*\*\*\*\*\*\*\* ansible\_connection: netconf ansible\_become: yes ansible\_become\_method: enable ansible\_become\_user: root ansible\_become\_password: \*\*\*\*\*\*\*\*\*\* [root@lonans01 juniperymls]#

---

<div class="post-metadata">

**Author:** ![ptn](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/ptn/32/481_2.png) [@ptn](https://forum.ansible.com/u/ptn)\
**Post date:** [November 1, 2023, 5:12pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/2 "2023-11-01T17:12:05Z")

</div>

Hi,

Not sure about this, but it seems to me you are using `ansible_connection: netconf`, whereas [module doc](https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_scp_module.html#notes) is stating:

> - Works with `local` connections only.
> - Since this module uses junos-eznc to establish connection with junos device the netconf configuration parameters needs to be passed using module options for example `ssh_config` unlike other junos modules that uses `netconf` connection type.

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 1, 2023, 10:16pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/3 "2023-11-01T22:16:32Z")

</div>

Hello,

This reminds me of another thread from a few weeks ago… Check this out just in case:

> [@Not able to push playbook to Juniper Switch](http://forum.ansible.com/t/not-able-to-push-playbook-to-juniper-switch/1778/5):
>
> Is netconf enabled on the Juniper device? You can use the junos\_netconf module to enable it: [junipernetworks.junos.junos\_netconf module – Configures the Junos Netconf system service — Ansible Documentation](https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_netconf_module.html)

Cheers!

---

<div class="post-metadata">

**Author:** ![G24joshi](https://avatars.discourse-cdn.com/v4/letter/g/258eb7/32.png) [@G24joshi](https://forum.ansible.com/u/G24joshi)\
**Post date:** [November 15, 2023, 5:10pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/4 "2023-11-15T17:10:25Z")

</div>

Hi All,

Still I am unable to copy a file from my ansible server to juniper switch. Please help me to resolve the issue.

I am trying with 2 methods to copy from ansible server to juniper switch.

Method 1. Below command is working fine if I run this in juniper switch but I am unable to push this command from ansible server to juniper switch.

> file copy ftp://user1:userpass@ftp-server-ip/abc4 /var/tmp/abc4

Method2. I am trying to use ansible module “junipernetworks.junos.junos\_scp” to copy file from ansible to switch but this is giving me error “You must provide either ‘host’ or ‘sock\_fd’ value”.

Playbook:

- hosts: juniperswitch  
gather\_facts: no  
connection: local

find below error.

The full traceback is:  
File “/root/.ansible/collections/ansible\_collections/junipernetworks/junos/plugins/modules/junos\_scp.py”, line 224, in main  
device = get\_device(module)  
File “/root/.ansible/collections/ansible\_collections/junipernetworks/junos/plugins/module\_utils/network/junos/junos.py”, line 155, in get\_device  
device = Device(host, \*\*kwargs)  
File “/usr/local/lib/python3.8/site-packages/jnpr/junos/device.py”, line 1263, in **init**  
raise ValueError(“You must provide either ‘host’ or ‘sock\_fd’ value”)  
fatal: [67.4.42.33]: FAILED! =\> {  
“changed”: false,  
“invocation”: {  
“module\_args”: {  
“dest”: “/var/tmp/”,  
“provider”: {},  
“recursive”: false,  
“remote\_src”: true,  
“src”: [  
“/tmp/abc9.txt”  
],  
“ssh\_config”: null,  
“ssh\_private\_key\_file”: null  
}  
},  
“msg”: “You must provide either ‘host’ or ‘sock\_fd’ value”  
}

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [November 16, 2023, 1:49pm UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/5 "2023-11-16T13:49:11Z")

</div>

Hey there, @G24joshi

> [@G24joshi](#):
>
> Method2. I am trying to use ansible module “junipernetworks.junos.junos\_scp” to copy file from ansible to switch but this is giving me error “You must provide either ‘host’ or ‘sock\_fd’ value”.
> 
> Playbook:
> 
> - hosts: juniperswitch  
> gather\_facts: no  
> connection: localtasks:
> - name: run show version on remote devices  
> junipernetworks.junos.junos\_scp:  
> src: /tmp/abc9.txt  
> dest: /var/tmp/  
> remote\_src: true

This module is deprecated, just check-out the docs:

[https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos\_scp\_module.html#deprecated](https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_scp_module.html#deprecated)

They suggest using these modules instead:

[ansible.netcommon.net\_get](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_get_module.html#ansible-collections-ansible-netcommon-net-get-module)  
[ansible.netcommon.net\_put](https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/net_put_module.html#ansible-collections-ansible-netcommon-net-put-module)

---

<div class="post-metadata">

**Author:** ![jbericat](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jbericat/32/627_2.png) [@jbericat](https://forum.ansible.com/u/jbericat)\
**Post date:** [December 3, 2023, 6:55am UTC](https://forum.ansible.com/t/unable-to-copy-file-from-ansible-server-to-juniper-switch/2079/6 "2023-12-03T06:55:37Z")

</div>

Hello there @G24joshi ,

I was reviewing some older unresolved posts on the #network-automation tag and came across this one from a few weeks ago. Are you still in need of help with this one? I’m not sure if you did see the latest answers…

Also, it would be awesome if you applied the proper formatting to the code snippets you attach on your posts, this will improve readability a lot ☺ Thanks a lot in advance! You can do this just by selecting the related text and clicking onto the “preformatted text” \</\> icon on the editor, by the way (you will find it inside the gear icon if you’re using your smartphone).

Best regards
