EOX GitLab Instance
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prometheus role
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ansible-public
prometheus role
Commits
f460230c
Commit
f460230c
authored
1 year ago
by
Karl Grube
Browse files
Options
Downloads
Patches
Plain Diff
cleaned up the etc_hosts file
parent
4bdb9952
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tasks/etc_hosts.yml
+110
-0
110 additions, 0 deletions
tasks/etc_hosts.yml
tasks/hellsing_hosts_ipv6.yml
+0
-81
0 additions, 81 deletions
tasks/hellsing_hosts_ipv6.yml
tasks/main.yml
+10
-3
10 additions, 3 deletions
tasks/main.yml
with
120 additions
and
84 deletions
tasks/etc_hosts.yml
0 → 100644
+
110
−
0
View file @
f460230c
---
-
name
:
block of etc host config
block
:
-
name
:
Determine service interface
set_fact
:
current_host_service_interface
:
"
{{
item.keys()
|
difference(['service'])
|
first
}}"
with_items
:
"
{{
my_interfaces
}}"
when
:
-
"
'service'
in
item"
-
item.service == True
delegate_to
:
"
{{prometheus_peer}}"
-
name
:
Capture IPv6 address of the current host
set_fact
:
current_host_ipv6
:
"
{{
hostvars[inventory_hostname]['ansible_'
+
current_host_service_interface]['ipv6']
|
selectattr('scope',
'equalto',
'global')
|
map(attribute='address')
|
first
}}"
when
:
-
"
'ansible_'
+
current_host_service_interface
in
hostvars[inventory_hostname]"
-
"
'ipv6'
in
hostvars[inventory_hostname]['ansible_'
+
current_host_service_interface]"
delegate_to
:
"
{{prometheus_peer}}"
-
name
:
Update /etc/hosts with IPv6 address of current host
lineinfile
:
path
:
/etc/hosts
line
:
"
{{
current_host_ipv6
}}
{{
prometheus_peer
}}"
state
:
present
regex
:
"
^.*{{
prometheus_peer
}}.*"
when
:
-
current_host_ipv6 is defined
-
current_host_ipv6 != ''
-
name
:
reset current_host_ipv6
set_fact
:
current_host_ipv6
:
'
'
tags
:
etc_hosts
####BEGIN on the hellsing group, specific lines in /etc/hosts file
#- name: Determine service interface
# set_fact:
# service_interface: "{{ item.keys() | difference(['service']) | first }}"
# with_items: "{{ my_interfaces }}"
# when:
# - "'service' in item"
# - item.service == True
##debugging
#- name: Debug service interface
# debug:
# msg: "Service interface: {{ service_interface }}"
#
#- name: Capture IPv6 address of the current host
# set_fact:
# current_host_ipv6: "{{ hostvars[inventory_hostname]['ansible_' + service_interface]['ipv6'] | selectattr('scope', 'equalto', 'global') | map(attribute='address') | first }}"
# when:
# - "'ansible_' + service_interface in hostvars[inventory_hostname]"
# - "'ipv6' in hostvars[inventory_hostname]['ansible_' + service_interface]"
##debugging
#- name: Debug ipv6 current host
# debug:
# msg: "ipv6 {{ inventory_hostname }}: {{ current_host_ipv6 }}"
#
#
#
#- name: Determine the other host in the hellsing group
# set_fact:
# other_host: "{{ prometheus_peers | reject('equalto', inventory_hostname) | first }}"
# when: groups['hellsing'] | length < 3
# run_once: true
##debugging
#- name: Debug ipv6 current host
# debug:
# msg: "The other host is: {{ other_host }}"
#
#- name: Gather facts from other hellsing hosts
# setup:
# delegate_to: "{{ other_host }}"
# run_once: true
# register: remote_facts
#
#- name: Set fact for remote host
# set_fact:
# other_host_facts: "{{ remote_facts.ansible_facts }}"
#
#- name: Capture IPv6 address of the other host now
# set_fact:
# other_host_ipv6: "{{ other_host_facts['ansible_' + service_interface]['ipv6'] | selectattr('scope', 'equalto', 'global') | map(attribute='address') | first }}"
# when:
# - "'ansible_' + service_interface in other_host_facts"
# - "'ipv6' in other_host_facts['ansible_' + service_interface]"
##debugging
#- name: Debug ipv6 current host
# debug:
# msg: "The other host has the IP: {{ other_host_ipv6 }}"
#
##### Update the hosts file now
#- name: Update /etc/hosts with IPv6 address of current host
# lineinfile:
# path: /etc/hosts
# line: "{{ current_host_ipv6 }} {{ inventory_hostname }}"
# state: present
# when:
# - current_host_ipv6 is defined
# - current_host_ipv6 != ''
#
#- name: Update /etc/hosts with IPv6 address of the other host
# lineinfile:
# path: /etc/hosts
# line: "{{ other_host_ipv6 }} {{ other_host }}"
# state: present
# when:
# - other_host_ipv6 is defined
# - other_host_ipv6 != ''
# - other_host is defined
#
####END of the script for adding specific lines on an Hellsing server
This diff is collapsed.
Click to expand it.
tasks/hellsing_hosts_ipv6.yml
deleted
100644 → 0
+
0
−
81
View file @
4bdb9952
---
###BEGIN on the hellsing group, specific lines in /etc/hosts file
-
name
:
Determine service interface
set_fact
:
service_interface
:
"
{{
item.keys()
|
difference(['service'])
|
first
}}"
loop
:
"
{{
my_interfaces
}}"
when
:
-
"
'service'
in
item"
-
item.service == True
run_once
:
true
#debugging
-
name
:
Debug service interface
debug
:
msg
:
"
Service
interface:
{{
service_interface
}}"
-
name
:
Capture IPv6 address of the current host
set_fact
:
current_host_ipv6
:
"
{{
hostvars[inventory_hostname]['ansible_'
+
service_interface]['ipv6']
|
selectattr('scope',
'equalto',
'global')
|
map(attribute='address')
|
first
}}"
when
:
-
"
'ansible_'
+
service_interface
in
hostvars[inventory_hostname]"
-
"
'ipv6'
in
hostvars[inventory_hostname]['ansible_'
+
service_interface]"
#debugging
-
name
:
Debug ipv6 current host
debug
:
msg
:
"
ipv6
{{
inventory_hostname
}}:
{{
current_host_ipv6
}}"
-
name
:
Determine the other host in the hellsing group
set_fact
:
other_host
:
"
{{
groups['hellsing']
|
reject('equalto',
inventory_hostname)
|
first
}}"
when
:
groups['hellsing'] | length <
3
run_once
:
true
#debugging
-
name
:
Debug ipv6 current host
debug
:
msg
:
"
The
other
host
is:
{{
other_host
}}"
-
name
:
Gather facts from other hellsing hosts
setup
:
delegate_to
:
"
{{
other_host
}}"
run_once
:
true
register
:
remote_facts
-
name
:
Set fact for remote host
set_fact
:
other_host_facts
:
"
{{
remote_facts.ansible_facts
}}"
-
name
:
Capture IPv6 address of the other host now
set_fact
:
other_host_ipv6
:
"
{{
other_host_facts['ansible_'
+
service_interface]['ipv6']
|
selectattr('scope',
'equalto',
'global')
|
map(attribute='address')
|
first
}}"
when
:
-
"
'ansible_'
+
service_interface
in
other_host_facts"
-
"
'ipv6'
in
other_host_facts['ansible_'
+
service_interface]"
#debugging
-
name
:
Debug ipv6 current host
debug
:
msg
:
"
The
other
host
has
the
IP:
{{
other_host_ipv6
}}"
#### Update the hosts file now
-
name
:
Update /etc/hosts with IPv6 address of current host
lineinfile
:
path
:
/etc/hosts
line
:
"
{{
current_host_ipv6
}}
{{
inventory_hostname
}}"
state
:
present
when
:
-
current_host_ipv6 is defined
-
current_host_ipv6 != ''
-
name
:
Update /etc/hosts with IPv6 address of the other host
lineinfile
:
path
:
/etc/hosts
line
:
"
{{
other_host_ipv6
}}
{{
other_host
}}"
state
:
present
when
:
-
other_host_ipv6 is defined
-
other_host_ipv6 != ''
-
other_host is defined
###END of the script for adding specific lines on an Hellsing server
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tasks/main.yml
+
10
−
3
View file @
f460230c
...
...
@@ -55,6 +55,13 @@
description
:
'
Prometheus
server'
tags
:
label
-
import_tasks
:
hellsing_hosts_ipv6.yml
tags
:
hosts_ipv6
when
:
use_service_vrf and inventory_hostname in groups['hellsing']
\ No newline at end of file
-
include_tasks
:
etc_hosts.yml
tags
:
etc_hosts
loop_control
:
loop_var
:
prometheus_peer
with_items
:
"
{{prometheus_peers}}"
when
:
-
use_service_vrf is defined
-
prometheus_peers is defined
-
my_interfaces is defined
-
prometheus_peer != inventory_hostname
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment