Skip to content

Commit

Permalink
add loop
Browse files Browse the repository at this point in the history
  • Loading branch information
xanhacks committed Oct 26, 2024
1 parent c34757f commit cea8600
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
31 changes: 27 additions & 4 deletions ansible/roles/monitoring/tasks/panel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,43 @@
- { src: ".env", dest: ".env" }

# ansible -i inventories/prod -m setup heroctf-static-1
- name: Collect IP addresses from challenges
- name: Collect IP addresses from challenges (cAdvisor)
ansible.builtin.set_fact:
cadvisor_targets: >-
{% for host in groups['static-challenges'] + groups['dynamic-challenges'] -%}
, "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:1080"
- targets:
- "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:1080"
labels:
instance: "containers-{{ hostvars[host]['ansible_hostname'] }}"
{{''}}
{%- endfor -%}
- name: Collect IP addresses from challenges
- name: Collect IP addresses from challenges (node-exporter)
ansible.builtin.set_fact:
nodeexporter_targets: >-
{% for host in groups['static-challenges'] + groups['dynamic-challenges'] -%}
, "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:9100"
- targets:
- "{{ hostvars[host]['ansible_eth1']['ipv4']['address']}}:9100"
labels:
instance: "vm-{{ hostvars[host]['ansible_hostname'] }}"
{{''}}
{%- endfor -%}
# - name: Collect IP addresses from challenges (/etc/hosts)
# ansible.builtin.set_fact:
# hosts_content: >-
# {% for host in groups['static-challenges'] + groups['dynamic-challenges'] %}
# {{ hostvars[host]['ansible_eth1']['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }}
# {% endfor %}

# - name: Populate /etc/hosts with 'hosts_content'
# ansible.builtin.lineinfile:
# path: /etc/hosts
# line: "{{ item }}"
# state: present
# loop: "{{ hosts_content.splitlines() }}"
# become: true

- name: "Setup Prometheus configuration"
ansible.builtin.template:
src: prometheus.yml.j2
Expand Down
16 changes: 14 additions & 2 deletions ansible/roles/monitoring/templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@ scrape_configs:

- job_name: "cadvisor"
static_configs:
- targets: ["cadvisor:8080", "35.180.196.232:8080" {{ cadvisor_targets }}]
- targets:
- "35.180.196.232:8080"
labels:
instance: "containers-ctfd"
- targets:
- "cadvisor:8080"
labels:
instance: "containers-deploy-dynamic"
{{ cadvisor_targets }}

- job_name: "node"
static_configs:
- targets: ["node_exporter:9100" {{ nodeexporter_targets }}]
- targets:
- "node_exporter:9100"
labels:
instance: "vm-deploy-dynamic"
{{ nodeexporter_targets }}

0 comments on commit cea8600

Please sign in to comment.