Skip to content

Instantly share code, notes, and snippets.

@senorsmile
Forked from viesti/filters.py
Last active September 17, 2015 20:04
Show Gist options
  • Select an option

  • Save senorsmile/acc08f48606a0ba3e1ef to your computer and use it in GitHub Desktop.

Select an option

Save senorsmile/acc08f48606a0ba3e1ef to your computer and use it in GitHub Desktop.
Ansible filter plugin to create rules fo ec2_group
def make_rules(hosts, ports, proto):
return [{"proto": proto,
"from_port": port,
"to_port": port,
"cidr_ip": host} for host in hosts for port in map(int, ports.split(","))]
class FilterModule(object):
def filters(self):
return {'make_rules': make_rules}
usage:
random_hosts:
- 192.168.1.2/32
- 172.16.0.2/32
ec2_group:
rules: "{{ random_hosts | make_rules('22,8080', 'tcp') }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment