1
votes

I have executed a ansible script on my machine. What is does is

1.Copy a file from my machine to a docker container running on a remote machine

file.pb

2.Execute a command on docker container. That command uses the copied file & sign it.

This is the command

peer channel signconfigtx -f file.pb

Now i want to again copy this signed file to another machine after it is signed in the same ansible script from the docker container where it is now.

I want try SCP but not sure how it will work because it will ask for password.

Can anyone suggest me how can i do this ?

EDIT:

I tried on my local machine to fetch files from remote server but it i get below error

fatal: [user1]: FAILED! => {"msg": "Unable to create local directories(/home/dhiraj/ansible_practise/playlist/fetched/user1/home/user1/Documents/Blockchain/network/scripts): [Errno 20] Not a directory: '/home/dhiraj/ansible_practise/playlist/fetched/user1'"}

below is my ansible script

 - name:  Fetching a file from remote server
      fetch:
        src: "/home/user1/Documents/Blockchain/network/scripts/file.pb"
        dest: fetched
2
SCP wouldn’t ask for a password if you configure passwordless key authentication to the host.masseyb
run mkdir fetched to create dest dest: fetched. Do you want to scp files to / from docker container running in which machine? same ansible server or remote machine? What is the docker image which is running? You will need ssh server in that image. Please update the question with these details. However, I would suggest to use a persistent volume in the host machine (where docker container runs) and use it, instead of complicating.Prakash Krishna
Already created 'fetched' folder. docker container is running on remote machine & i am able to access it. I am able to access the directory which is mounted to docker container.TechChain

2 Answers

1
votes

There are more options.

1) scp from docker to another machine

  • Put public key of the user running scp at Docker to authorized_key of the user you connect at another machine.
  • At docker run command: scp file.pb user@another_machine:file.pdb

2) fetch and copy

  • fetch from docker to your machine

  • copy from your machine to another machine

3) fetch and pull

  • fetch from docker to your machine
  • At another machine run ansible-pull and run the playbook that would fetch the file from your machine.

4) Run scp at another machine ...

1
votes

Instead of copying files directly bertween servers what i have done is i used fetch module of ansible. In fetch i just had to define source path and destination path.

Here is sample

   - name:  Fetching a file from remote server
      fetch:
        src: "{{ DEST }}/Documents/Blockchain/network/scripts/file.pb"
        dest: /home/fetched/
        flat: yes // it will not create dir strcuture as same as source
        validate_checksum: false