I want to copy the remote server file to my local server but I am not able to copy

Hello All,

Following are my details regarding copying from the remote machine, I have to copy the propertie file from the remote test server to the local ansible server.

I have achieved this task using ssh command as below:

sshpass -p jpass scp -o StrictHostKeyChecking=no “testuser@testmachine:/opt/testserver/jetty/jetty-distribution-9.3/etc/core/application.properties” “/opt/jenkins/sharedspace/BackupRestore/resources”

However, my I want this to be converted to ansible copy format like this but somehow I am not able to copy that remote file. (Only thing is one should copy that file as become_user: root which I am already doing)

  • hosts: testserver.testing.com (This is ansible server host)
    remote_user: sampleuser
  • name: webapps copy
    become: yes
    become_user: root
    copy:
    src: /opt/testserver/jetty/jetty-distribution-9.3/etc/core/application.properties
    dest: /opt/jenkins/sharedspace/BackupRestore/resources
    owner: testuser
    group: testuser

Getting a below issue:

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AnsibleFileNotFound: Could not find or access '/opt/testserver/jetty/9.3/webapps/

Could anyone know on this more?

Thanks in Advanced.

Thanks,
Sachi

You probably want the fetch module
https://docs.ansible.com/ansible/latest/modules/fetch_module.html#fetch-module

Or slurp will load into memory