I'm trying to learn Ansible. I'm working on creating an instance and uploading a file into it, the file i want to put into the ec2 instance is in stored in S3, but it keeps saying that the destination inside the c2 doesn't exist, it does exist though.
This is which is failing, everything else before that including the creation of instance is working fine :
- name: Deploy war file
aws_s3:
bucket: "{{ war_bucket }}"
object: "{{ war_file }}"
dest: "{{ war_deploy_path }}/{{ war_file }}"
mode: get
overwrite: no
register: war_downloaded
And this is how i declared my variables :
war_file: file.war
war_bucket: ansible-bucket
war_deploy_path: /opt/folder/file.war
And this is the error I get :
[Errno 2] No such file or directory: '/opt/folder/file.war.1f1ccA91'
Why is it adding this weird code "1f1cA91" ? Is it causing the problem?
Update : I tried changing the destination from "{{ war_deploy_path }}/{{ war_file }}" to "{{ war_deploy_path }}" but the same problem persists, only the error is [Errno 2] No such file or directory: '/opt/folder.Ac2926c3'
now.
Important Update 2 : Ok, so for the sake of testing, i decided to create the same path in my local machine, and to my surprise, this script is actually running it on my local machine instead of the ec2 instance lol, so now, how do i make it run on the ec2 instance xD.
To create a host in ansible and then work on it in the same playbook is possible but requires some on the fly changes to the inventory file and a re-read of the inventory in your playbook.
First, add a place holder to your inventory file like:
Second, in your playbook you're going to need two sections, one to run the local job and the second to run against the host(s) you created from the first section. In the first part, you'll create the hosts and then add the host IP to the inventory you created above. Then you'll tell ansible to re-read the inventory with the
meta
command and then wait for the host(s) to come up with apause
command. Here's an example:Then you create another entry in the same playbook to copy your file. I don't have pip installed on my hosts by default so added that just in case you're in the same boat:
Here's the complete playbook in case you're still confused:
References
Ansible Meta Module
P.S. I only tested this building one host, if you build multiples your mileage may vary.