Skip to content

Instantly share code, notes, and snippets.

@levlas
Created October 1, 2017 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save levlas/69ee2c8b8cb64d172cbe073170dbb948 to your computer and use it in GitHub Desktop.
Save levlas/69ee2c8b8cb64d172cbe073170dbb948 to your computer and use it in GitHub Desktop.
Ansible templating with variables from inventory
[aws]
aws_u ansible_host=5.5.1.1
[k8s]
[arub]
flok ansible_host=8.2.2.5
[py3-hosts]
aws_u
[py3-hosts:vars]
ansible_python_interpreter=/usr/bin/python3
[telegraf_clients:children]
aws
k8s
arub
[prometheus]
dev ansible_host=1.1.6.1
---
# Telegraf
- hosts: telegraf_clients
become: true
tasks:
- name: check or create directory /usr/local/bin
file:
path: /usr/local/bin
state: directory
mode: 0755
[...]
# Prometheus
- hosts: prometheus
become: true
tasks:
- name: copy prometheus config file
template:
src: ./files/prometheus.j2
dest: /mnt/prometheus/config/prometheus.yml
scrape_configs:
{% for host_group in telegraf_clients %}
- job_name: '{{ host_group }}'
scrape_interval: 10s
static_configs:
- targets: [{% for host_ip in host_group %}'{{ host_ip }}:9126'{% if not loop.last %},{% endif %}{% endfor %}]
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment