Created
October 1, 2017 18:05
-
-
Save levlas/69ee2c8b8cb64d172cbe073170dbb948 to your computer and use it in GitHub Desktop.
Ansible templating with variables from inventory
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
[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 |
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
--- | |
# 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 |
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
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