Last active
February 16, 2018 08:43
-
-
Save smarthall/1e302b40f38ddd4e218d to your computer and use it in GitHub Desktop.
Getting lists from dictionaries in Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In Ansible lots of things take lists (or comma seperated | |
# strings), however lots of things return dicts. One | |
# example of this is the hostvars and groups variable. | |
# | |
# groups returns a list of machines in a group, and | |
# hostvars is a dict containing all the hosts. So if you | |
# need a list of ip addresses of those hosts for the | |
# route53 module you cant. This filter makes this possible. | |
def fetchlistfromdict(d, l): | |
result = [] | |
for item in l: | |
result.append(d[item]) | |
return result | |
class FilterModule(object): | |
def filters(self): | |
return { | |
'fetchlistfromdict': fetchlistfromdict, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is really useful filter.
Did you try to push it to ansible core or maybe is it there already? I can't find it...