Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created May 19, 2020 16:30
Show Gist options
  • Save luckylittle/54ccc322e4ac07ecc391431beab8573a to your computer and use it in GitHub Desktop.
Save luckylittle/54ccc322e4ac07ecc391431beab8573a to your computer and use it in GitHub Desktop.
Red Hat Ansible aws_s3 module filter example
---
# Tested on Ansible 2.9.4
# aws_s3 module lists all objects, including folders - that is sometimes undesirable
# Copyright (c) 2020 Lucian Maly, Red Hat
- hosts: localhost
gather_facts: false
vars:
s3_keys:
- "ESRI_PATCHES/ArcGIS_Server/1071/"
- "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-GG-Patch.msp"
- "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-MWJUN2019SUC-Patch.msp"
- "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-SSP-Patch.msp"
- "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-TD-Patch.msp"
- "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-USR-Patch.msp"
tasks:
- name: List without the root folder object (only the files)
debug:
msg: "{{ item }}"
loop:
- "{{ s3_keys | select('match', '^.*.msp$') | list }}"
@luckylittle
Copy link
Author

Returns:

{
  "msg": [
    "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-GG-Patch.msp",
    "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-MWJUN2019SUC-Patch.msp",
    "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-SSP-Patch.msp",
    "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-TD-Patch.msp",
    "ESRI_PATCHES/ArcGIS_Server/1071/ArcGIS-1071-S-USR-Patch.msp"
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment