Created
June 26, 2018 18:13
-
-
Save cjmatta/b33dac35cc1850391e7c9dbc1971ef87 to your computer and use it in GitHub Desktop.
Small jinja2-based template script for creating an inventory file for https://github.com/confluentinc/cp-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
#!/usr/bin/env python | |
# This script is meant to be used in conjunction with the JSON formatted | |
# output of `https://github.com/cjmatta/cp-poc-terraform | |
# Usage: terraform output -json` | ./create_ansible_inventory.py | |
import json | |
from jinja2 import Template | |
import sys | |
template = Template("""all: | |
vars: | |
ansible_connection: ssh | |
ansible_ssh_user: centos | |
ansible_become: true | |
security_mode: sasl_ssl | |
preflight: | |
hosts: | |
{%- for broker in broker_private_dns.value %} | |
{{broker}}: | |
{%- endfor %} | |
{%- for worker in worker_private_dns.value %} | |
{{worker}}: | |
{%- endfor %} | |
ssl_CA: | |
hosts: | |
{{broker_private_dns.value[0]}}: | |
zookeeper: | |
hosts: | |
{%- for broker in broker_private_dns.value %} | |
{{broker}}: | |
{%- endfor %} | |
broker: | |
hosts: | |
{%- for broker in broker_private_dns.value %} | |
{{broker}}: | |
kafka: | |
broker: | |
id: {{loop.index}} | |
{%- endfor %} | |
schema-registry: | |
hosts: | |
{%- for worker in worker_private_dns.value %} | |
{{worker}}: | |
{%- endfor %} | |
control-center: | |
hosts: | |
{{worker_private_dns.value[0]}}: | |
confluent: | |
control: | |
center: | |
config: | |
confluent.controlcenter.connect.cluster: {% for worker in worker_private_dns.value -%} | |
{{worker}}:8083 | |
{%- if not loop.last %},{% endif %} | |
{%- endfor %} | |
connect-distributed: | |
hosts: | |
{%- for worker in worker_private_dns.value %} | |
{{worker}}: | |
{%- endfor %} | |
kafka-rest: | |
hosts: | |
{%- for worker in worker_private_dns.value %} | |
{{worker}}: | |
{%- endfor %} | |
ksql: | |
hosts: | |
{%- for worker in worker_private_dns.value %} | |
{{worker}}: | |
{%- endfor %} | |
tools: | |
hosts: | |
{{worker_private_dns.value[0]}}:""") | |
def read_stdin_json(): | |
try: | |
input_json = json.loads(sys.stdin.read()) | |
return input_json | |
except ValueError, e: | |
print "Error: STDIN is not JSON" | |
sys.exit(1) | |
input = read_stdin_json() | |
print(template.render(input)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment