AWS configuration
SSM State manager : Association Parameters
documentParameters with an archive (zip) containing multiple yml files
{ "InstallDependencies":"False", "SourceType":"S3", "SourceInfo":"{\"path\":\"https://name_of_bucket_hosting_sources.s3-eu-west-42.amazonaws.com/prefix_key/archive.zip\"}", "PlaybookFile":"main.yml" }documentParameters with only one yml files
{ "InstallDependencies":"False", "SourceType":"S3", "SourceInfo":"{\"path\":\"https://name_of_bucket_hosting_sources.s3-eu-west-42.amazonaws.com/prefix_key/playbook.yml\"}", "PlaybookFile":"playbook.yml" }sourceInfo
{ "name": "AWS-ApplyAnsiblePlaybooks" }* Association Target
Depending on where you want to run the playbook, select what's appropriate
Ansible playbook
example : daily export from an EC2 instance directory to an s3 bucket
- hosts: localhost
become: yes
become_method: sudo
tasks:
- name: Find zips in /path/to/data/*.zip older than 7d
find:
paths: /path/to/data/
patterns: '*.zip'
age: 7d
register: files_to_delete
- name: Remove zips in /path/to/data/ older than 7d
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
- name: Upload content of /path/to/data/ directory, ommiting structure-*.zip files
community.aws.s3_sync:
bucket: target-s3-share-name
key_prefix: s3-prefix-dir-name/subdirectory/
file_root: /path/to/data/
include: "*.zip"
exclude: "structure-*.zip"
delete: no # if set to yes, removes remote files that exist in bucket but are not present in the file root.
- name: Upload content of /path/to/data/ directory
community.aws.s3_sync:
bucket: target-s3-share-name
key_prefix: s3-prefix-dir-name/subdirectory/
file_root: /path/to/data/
include: "*"
become: yes
become_method: sudo
tasks:
- name: Find zips in /path/to/data/*.zip older than 7d
find:
paths: /path/to/data/
patterns: '*.zip'
age: 7d
register: files_to_delete
- name: Remove zips in /path/to/data/ older than 7d
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
- name: Upload content of /path/to/data/ directory, ommiting structure-*.zip files
community.aws.s3_sync:
bucket: target-s3-share-name
key_prefix: s3-prefix-dir-name/subdirectory/
file_root: /path/to/data/
include: "*.zip"
exclude: "structure-*.zip"
delete: no # if set to yes, removes remote files that exist in bucket but are not present in the file root.
- name: Upload content of /path/to/data/ directory
community.aws.s3_sync:
bucket: target-s3-share-name
key_prefix: s3-prefix-dir-name/subdirectory/
file_root: /path/to/data/
include: "*"
References :
Aucun commentaire:
Enregistrer un commentaire