Skip to content

Instantly share code, notes, and snippets.

@halberom
Last active May 18, 2023 10:22
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save halberom/83a56f6f0b60c4afcf36fab862f1a6d2 to your computer and use it in GitHub Desktop.
Save halberom/83a56f6f0b60c4afcf36fab862f1a6d2 to your computer and use it in GitHub Desktop.
ansible - example of using lookup and a template to generate dynamic list entries for modules
#jinja2:trim_blocks: True, lstrip_blocks: True
targets:
{% for privnet in all_private_subnets %}
- subnet_id: "{{ privnet }}"
security_groups: [ "{{ sg.group_id }}" ]
{% endfor %}
{% for pubnet in all_public_subnets %}
- subnet_id: "{{ pubnet }}"
security_groups: [ "{{ sg.group_id }}" ]
{% endfor %}
---
- hosts: localhost
gather_facts: False
connection: local
tasks:
- efs:
state: present
name: "{{ region }}-{{ service }}"
tags:
name: "{{ region }}-{{ service }}"
purpose: "{{ service }}"
deploy_env: "{{ deploy_env }}"
vpc: "{{ vpc_id }}"
targets: "{{ lookup('template', 'efs_targets.j2') | from_yaml }}"
register: ec2_efs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment