Skip to content

Instantly share code, notes, and snippets.

@richm
Created October 29, 2020 20:01
Show Gist options
  • Save richm/dfa25020617ed3666af13aee86a2f7cf to your computer and use it in GitHub Desktop.
Save richm/dfa25020617ed3666af13aee86a2f7cf to your computer and use it in GitHub Desktop.
---
- name: set parameters for test
hosts: localhost
tasks:
- set_fact:
vpn_connections:
- type: psk
hosts:
hosta:
hostb:
- name: show connections
debug:
msg: conns {{ vpn_connections | to_nice_json }}
- name: add psk to each tunnel
set_fact:
vpn_connections: |
{% for tunnel in vpn_connections | selectattr("type", "equalto", "psk") %}
{% if "psk" not in tunnel %}
{% set _ = tunnel.__setitem__("psk", "need to create psk") %}
{% endif %}
{% endfor %}
{{ vpn_connections }}
- name: show connections again
debug:
msg: conns {{ vpn_connections | to_nice_json }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment