infra-role-icinga/tasks/hosts.yml

53 lines
1.6 KiB
YAML

---
- name: Get data centers
uri:
url: '{{ consul_url }}/datacenters'
register: data_centers
- name: Discover mailnode services
uri:
url: '{{ consul_url }}/service/statusd-mail?dc={{ item }}'
register: mail_servers
with_items: '{{ data_centers.json }}'
- name: Discover whisper services
uri:
url: '{{ consul_url }}/service/statusd-whisper?dc={{ item }}'
register: whisper_servers
with_items: '{{ data_centers.json }}'
- name: Discover eth fleet hosts
uri:
url: '{{ consul_url }}/nodes?node-meta=env:eth&dc={{ item }}'
register: statusd_hosts
with_items: '{{ data_centers.json }}'
- name: Combine data centers into one list
set_fact:
statusd_hosts: '{{ statusd_hosts.results | sum(attribute="json", start=[]) }}'
mail_servers: '{{ mail_servers.results | sum(attribute="json", start=[]) }}'
whisper_servers: '{{ whisper_servers.results | sum(attribute="json", start=[]) }}'
- name: Merge all statusd services
set_fact:
statusd_services: '{{ whisper_servers + mail_servers }}'
- name: Extract tags from services list
set_fact:
host_tags: '{{ statusd_hosts | map(attribute="Meta") | map(attribute="stage") | list | unique }}'
service_tags: '{{ statusd_services | sum(attribute="ServiceTags", start=[]) | unique }}'
- name: Create folder for hosts
file:
path: '{{ icinga_conf_d_path }}/hosts'
state: directory
owner: '{{ icinga_api_host_uid }}'
group: docker
- name: Generate host definitions for eth fleet
template:
src: icinga_hosts.conf.j2
dest: '{{ icinga_conf_d_path }}/hosts/eth_fleets.conf'
owner: '{{ icinga_api_host_uid }}'
group: docker