Unable to copy file from ansible server to Juniper Switch

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

    tasks:

    • name: copy file from Ansible to Switch
      junipernetworks.junos.junos_scp:
      src: testing6.txt
      dest: /var/tmp/

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

Hi,

Not sure about this, but it seems to me you are using ansible_connection: netconf, whereas module doc 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.
1 Like

Hello,

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

Cheers!

1 Like

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

    tasks:

    • name: run show version on remote devices
      junipernetworks.junos.junos_scp:
      src: /tmp/abc9.txt
      dest: /var/tmp/
      remote_src: true

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

Hey there, @G24joshi

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

https://docs.ansible.com/ansible/latest/collections/junipernetworks/junos/junos_scp_module.html#deprecated

They suggest using these modules instead:

ansible.netcommon.net_get
ansible.netcommon.net_put

1 Like

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