Ansible s3_sync to upload multiple files

Hi All,

I am trying to upload multiple yaml cloudformation templates to a s3 bucket using s3_sync. I have created a task in the playbook, looks like the tasks completed successfully but the file is not uploaded. Can someone please advise whether s3_sync is the proper method? If yes, can someone please help me identify what I have missed. Please find my playbook below:

Playbook

  • name: upload files rxgt-ps-cross-account-s3-sync
    s3_sync:
    region: “{{ account_config.1 }}”
    aws_access_key: “{{ account_config.0.sts_creds.access_key }}”
    aws_secret_key: “{{ account_config.0.sts_creds.secret_key }}”
    security_token: “{{ account_config.0.sts_creds.session_token }}”
    bucket: “{{ account_config.0.account_config.stacks[‘rxgt-ps-cross-account-s3-sync’].params.bucket }}”
    file_root: “{{ account_config.0.account_config.stacks[‘rxgt-ps-cross-account-s3-sync’].params.file_root }}”
    mode: “{{ account_config.0.account_config.stacks[‘rxgt-ps-cross-account-s3-sync’].params.mode }}”
    file_change_strategy: “{{ account_config.0.account_config.stacks[‘rxgt-ps-cross-account-s3-sync’].params.file_change_strategy }}”
    permission: “{{ account_config.0.account_config.stacks[‘rxgt-ps-cross-account-s3-sync’].params.permission }}”
    loop: “{{ assumed_roles_with_account_config.results|subelements(‘account_config.regions’, skip_missing=True) }}”
    loop_control:
    loop_var: account_config
    label: “{{ account_config.0.account_config.account_alias }}:{{ account_config.1 }}”
    tags:
    rxgt-ps-identity-stack-deploy

Account_config file

stacks:
rxgt-ps-cross-account-s3-sync:
params:
bucket: xxx-xx-xxxxxxxxxxx-eu-west-1-xxxxxxxxxx
file_root: /xxx-xxxx-xxxxxplatform/ansible/files/
mode: push
file_change_strategy: date_size
permission: public-read

Hi everyone,

I tried to debug s3_sync but one thing I noticed is s3_sync module does not have a destination path. It only has file_root and I ran this command from the source path “aws s3 sync . s3://bucketname/xxxx/test/”, it uploaded all the files to the destination. Then after I ran the playbook it completed successfully. Experts please advise if I miss something here.

Thanks
Kishore

This has been resolved by adding a new task for the cross account role to assume from the same account and updated the account config with local account parameters.