Ansible: Copying Files From Local Machine to AWS S3 Bucket in YAML
March 6, 2023 2023-06-30 2:34Ansible: Copying Files From Local Machine to AWS S3 Bucket in YAML
Hello World! This post you would get understand how to copy files or directories from Local Machine to S3 bucket using an Ansible. You can use the s3 module provided by Ansible.
We have written a simple Ansible playbook that demonstrates copying files from local to S3 bucket for restored it which deployed files in client instance.
Variables are {{APP_NAME}} and {{ S3_BUCKET_NAME }}, you have to specify in vars-main.yaml file.
Create a YAML file and add the code below,
---
- hosts: hostname
become: yes
become_user: username
## You can include vars_files
vars_files:
- vars-main.yml
## Copying files to S3 Bucket
- name: "copy to S3 bucket"
s3_sync:
bucket: {{S3_BUCKET_NAME}}
file_username: "/tmp/{{APP_NAME}}_rollback"
key_prefix: Deployment/{{APP_NAME}}_rollback
file_change_strategy: force
include: "*"
permission: private
mode: push
Now, run your playbook using the Ansible command, I hope so, It should be working good.