{%- set keyring = [] -%} {%- set bdb_config_path = {'path': ''} -%} {%- for host in bdb_hosts -%} {%- if host["name"] != ansible_hostname -%} {{- keyring.append(hostvars[host["name"]]["pub_key"]) -}} {%- else -%} {%- if bdb_config_path.update({'path': hostvars[host["name"]]["bdb_config"]}) -%} {%- endif -%} {%- endif -%} {%- endfor -%} {%- if keyring|length != 0 -%} #!/usr/bin/python import json with open('{{ bdb_config_path['path'] }}', 'r+') as f: data = json.load(f) del data['keyring'][:] data['keyring'] = {{ keyring }} f.seek(0) json.dump(data, f, indent=4) f.truncate() {%- endif -%}