Following questions involves use of YAML, BASH, SSH and Software called Ansible
I am trying to learn how to use a Linux environment (in my case a Ubuntu Windows Sub System) to copy a text file from my files to a remote instance (in this case Amazon Web Services) by connecting via SSH.
I have set up directories and files in Ubuntu like so:
I assume I now need to somehow add something in the text file my_hosts that will allow me to connect to the remote instance; and subsequently copy the text file.
In order to then run the process is use:
ansible-playbook -i hosts playbook.yml
But i don't know what to put in the my_hosts file or whether everything else i have done is correct.
I've tried my best to explain what I am trying to do, please ask any more questions to help clarify.
You will put the hostname you wish to use run ansible against.
In your case the hostname of amazon host written in that file.
Check out the /etc/ansible/hosts , it has comments about usage.
This is the default file used if you issue playbook without the -i parameter.
This presumes you have generated a ssh key for user you are issuing commands with and exchanged it with your amazon host.
See ssh-keygen and, since you are on Linux, ssh-copy-id if you haven't.
There is no need to use root accounts for any of the operations, only editing of default configuration files, which you are not doing.
It is also good to mention, using ansible to copy a file to one host is an overhead, since you can use scp to achieve the same.
If you require to execute several actions, copy files, start service(s), install packages on large number of servers ansible utility has a use case.
Otherwise it's like you are using a pneumatic hammer to kill a fly.
When running that command:
sudo scp -i ansible_instance_d**_*.pem "local_path_to_file" "ubuntu@ec2-**-***-**-.compute-1.amazonaws.com:/remote_path_to_file"
The 'permission denied' is probably on the remote system, not yours. You are attempting to write to the root folder, which isn't going to work. Be sure to tell scp exactly where you want the file to end up.
In that light, the 'sudo' is probably superfluous. You don't seem to need special permissions on your local system, and don't get elevated permissions on the remote one anyway.
Also, chmod 777 is not the magic sledgehammer to fix all problems. Try chmod 660, unless you really want to keep a world-writable script executable hanging around.