Skip to content

Commit 331d481

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Allow ELK7 roles to run with disabled ANSIBLE_INJECT_FACT_VARS"
2 parents 78bb145 + 1d52793 commit 331d481

File tree

34 files changed

+223
-176
lines changed

34 files changed

+223
-176
lines changed

elk_metrics_7x/installJournalbeat.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
meta: end_play
6464
when:
6565
- not (journal_dir.stat.exists | bool) or
66-
(ansible_service_mgr != 'systemd')
66+
(ansible_facts['service_mgr'] != 'systemd')
6767

6868
roles:
6969
- role: elastic_journalbeat
@@ -94,7 +94,7 @@
9494
meta: end_play
9595
when:
9696
- not (journal_dir.stat.exists | bool) or
97-
(ansible_service_mgr != 'systemd')
97+
(ansible_facts['service_mgr'] != 'systemd')
9898

9999
roles:
100100
- role: elastic_rollup

elk_metrics_7x/installMonitorStack.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
union(groups['memcached_all'] | default([])) |
2828
union(groups['memcached_all'] | default([]))
2929
)
30-
- ansible_service_mgr == 'systemd'
30+
- ansible_facts['service_mgr'] == 'systemd'
3131
tags:
3232
- always
3333

@@ -154,7 +154,7 @@
154154
post_tasks:
155155
- name: Find clouds config
156156
stat:
157-
path: "{{ ansible_env.HOME }}/.config/openstack/clouds.yaml"
157+
path: "{{ ansible_facts['env']['HOME'] }}/.config/openstack/clouds.yaml"
158158
register: clouds_config
159159

160160
- name: Find openstack release
@@ -174,9 +174,9 @@
174174
block:
175175
- name: Ensure disto packages are installed
176176
package:
177-
name: "{{ monitorstack_distro_packages[(ansible_distribution | lower)] }}"
177+
name: "{{ monitorstack_distro_packages[(ansible_facts['distribution'] | lower)] }}"
178178
state: "{{ monitorstack_package_state | default('present') }}"
179-
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
179+
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
180180

181181
- name: Refresh local facts
182182
setup:
@@ -218,7 +218,7 @@
218218

219219
- name: Copy the clouds config into monitorstack
220220
copy:
221-
src: "{{ ansible_env.HOME }}/.config/openstack/clouds.yaml"
221+
src: "{{ ansible_facts['env']['HOME'] }}/.config/openstack/clouds.yaml"
222222
dest: "/var/lib/monitorstack/.config/openstack/clouds.yaml"
223223
remote_src: yes
224224
when:

elk_metrics_7x/roles/elastic_apm_server/tasks/main.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@
1414
# limitations under the License.
1515

1616
- name: Gather variables for each operating system
17-
include_vars: "{{ item }}"
18-
with_first_found:
19-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
20-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
21-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
22-
- "{{ ansible_distribution | lower }}.yml"
23-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
24-
- "{{ ansible_os_family | lower }}.yml"
17+
include_vars: "{{ lookup('first_found', params) }}"
18+
vars:
19+
params:
20+
files:
21+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
22+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
23+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
24+
- "{{ ansible_facts['distribution'] | lower }}.yml"
25+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml"
26+
- "{{ ansible_facts['os_family'] | lower }}.yml"
27+
paths:
28+
- "{{ role_path }}/vars"
2529
tags:
2630
- always
2731

2832
- name: Ensure apm-server is installed
2933
package:
3034
name: "{{ apm_server_distro_packages }}"
3135
state: "{{ elk_package_state | default('present') }}"
32-
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
36+
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
3337
register: _package_task
3438
until: _package_task is success
3539
retries: 3

elk_metrics_7x/roles/elastic_auditbeat/tasks/main.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@
1414
# limitations under the License.
1515

1616
- name: Gather variables for each operating system
17-
include_vars: "{{ item }}"
18-
with_first_found:
19-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
20-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
21-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
22-
- "{{ ansible_distribution | lower }}.yml"
23-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
24-
- "{{ ansible_os_family | lower }}.yml"
17+
include_vars: "{{ lookup('first_found', params) }}"
18+
vars:
19+
params:
20+
files:
21+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
22+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
23+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
24+
- "{{ ansible_facts['distribution'] | lower }}.yml"
25+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml"
26+
- "{{ ansible_facts['os_family'] | lower }}.yml"
27+
paths:
28+
- "{{ role_path }}/vars"
2529
tags:
2630
- always
2731

@@ -31,13 +35,13 @@
3135
- auditbeat
3236
containerised: true
3337
when:
34-
- ansible_virtualization_type in ["systemd-nspawn", "lxc", "lxd", "podman", "docker", "systemd_container", "container"]
38+
- ansible_facts['virtualization_type'] in ["systemd-nspawn", "lxc", "lxd", "podman", "docker", "systemd_container", "container"]
3539

3640
- name: Ensure beat is installed
3741
package:
3842
name: "{{ auditbeat_distro_packages }}"
3943
state: "{{ elk_package_state | default('present') }}"
40-
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
44+
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
4145
register: _package_task
4246
until: _package_task is success
4347
retries: 3

elk_metrics_7x/roles/elastic_auditbeat/templates/auditbeat.yml.j2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ auditbeat.modules:
3434
# The auditd module collects events from the audit framework in the Linux
3535
# kernel. You need to specify audit rules for the events that you want to audit.
3636
- module: auditd
37-
{% if ansible_kernel is version('4.4', '>=') %}
37+
{% if ansible_facts['kernel'] is version('4.4', '>=') %}
3838
socket_type: {{ (apply_security_hardening | default(true) | bool) | ternary('multicast', 'unicast') }}
3939
{% endif %}
4040
resolve_ids: true
@@ -678,7 +678,7 @@ name: {{ elastic_hostname }}
678678
#kerberos.realm: ELASTIC
679679

680680
# ------------------------------ Logstash Output -------------------------------
681-
{{ elk_macros.output_logstash(inventory_hostname, logstash_data_hosts, ansible_processor_count) }}
681+
{{ elk_macros.output_logstash(inventory_hostname, logstash_data_hosts, ansible_facts['processor_count']) }}
682682

683683
# -------------------------------- Kafka Output --------------------------------
684684
#output.kafka:
@@ -1155,7 +1155,7 @@ setup.ilm.policy_file: "{{ ilm_policy_file_location }}/{{ ilm_policy_filename }}
11551155
{{ elk_macros.beat_logging('auditbeat', auditbeat_log_level) }}
11561156

11571157
# ============================= X-Pack Monitoring ==============================
1158-
{{ elk_macros.xpack_monitoring_elasticsearch('auditbeat', inventory_hostname, elasticsearch_data_hosts, ansible_processor_count, beats_system_username, elastic_cluster_uuid) }}
1158+
{{ elk_macros.xpack_monitoring_elasticsearch('auditbeat', inventory_hostname, elasticsearch_data_hosts, ansible_facts['processor_count'], beats_system_username, elastic_cluster_uuid) }}
11591159

11601160
# =============================== HTTP Endpoint ================================
11611161

elk_metrics_7x/roles/elastic_data_hosts/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# limitations under the License.
1515

1616
# This interface is used to determine cluster recovery speed.
17-
elastic_data_interface: "{{ ansible_default_ipv4['alias'] }}"
17+
elastic_data_interface: "{{ ansible_facts['default_ipv4']['alias'] }}"
1818

1919
# A list of interfaces/ports of the elasticsearch data nodes
2020
# to override the default of ansible_host:elastic_port

elk_metrics_7x/roles/elastic_data_hosts/vars/data-node-variables.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ _elasticsearch_discovery_seed_hosts: >-
9999
}}
100100
101101
elasticsearch_interface_speed: |-
102-
{% set default_interface_fact = hostvars[inventory_hostname]['ansible_' + (elastic_data_interface | replace('-', '_'))] %}
102+
{% set default_interface_fact = hostvars[inventory_hostname]['ansible_facts'][elastic_data_interface | replace('-', '_')] %}
103103
{% set speeds = [] %}
104104
{% if default_interface_fact['type'] == 'bridge' %}
105105
{% for interface in default_interface_fact['interfaces'] %}
106-
{% set interface_fact = hostvars[inventory_hostname]['ansible_' + (interface | replace('-', '_'))] %}
106+
{% set interface_fact = hostvars[inventory_hostname]['ansible_facts'][interface | replace('-', '_')] %}
107107
{% if 'speed' in interface_fact %}
108108
{% set speed = (interface_fact['speed'] | default(1000)) | string %}
109109
{% if speed == "-1" %}
@@ -158,9 +158,9 @@ logstash_data_node_details: >-
158158
master_node: "{{ (inventory_hostname in master_nodes) | ternary(true, false) }}"
159159
data_node: "{{ (inventory_hostname in data_nodes) | ternary(true, false) }}"
160160

161-
elastic_processors_floor: "{{ ((ansible_processor_count | int) - 1) }}"
161+
elastic_processors_floor: "{{ ((ansible_facts['processor_count'] | int) - 1) }}"
162162
elastic_processors_floor_set: "{{ ((elastic_processors_floor | int) > 0) | ternary(elastic_processors_floor, 1) }}"
163-
elastic_thread_pool_size: "{{ ((ansible_processor_count | int) >= 24) | ternary(23, elastic_processors_floor_set) }}"
163+
elastic_thread_pool_size: "{{ ((ansible_facts['processor_count'] | int) >= 24) | ternary(23, elastic_processors_floor_set) }}"
164164

165165
# Set a data node facts. The data nodes, in the case of elasticsearch are also
166166
# ingest nodes.

elk_metrics_7x/roles/elastic_dependencies/defaults/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#elastic_shared_fs_repos:
2222
# - fstype: nfs4
2323
# src: "<nfs-server-ip>:/esbackup"
24-
# opts: clientaddr="{{ ansible_eth1['ipv4']['address'] }}"
24+
# opts: clientaddr="{{ ansible_facts['eth1']['ipv4']['address'] }}"
2525
# path: "/elastic-backup"
2626
# state: mounted
2727

elk_metrics_7x/roles/elastic_dependencies/tasks/main.yml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@
3838
include_vars: "vars_{{ service_name }}.yml"
3939

4040
- name: Gather variables for each operating system
41-
include_vars: "{{ item }}"
42-
with_first_found:
43-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
44-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
45-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
46-
- "{{ ansible_distribution | lower }}.yml"
47-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
48-
- "{{ ansible_os_family | lower }}.yml"
41+
include_vars: "{{ lookup('first_found', params) }}"
42+
vars:
43+
params:
44+
files:
45+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
46+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
47+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
48+
- "{{ ansible_facts['distribution'] | lower }}.yml"
49+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml"
50+
- "{{ ansible_facts['os_family'] | lower }}.yml"
51+
paths:
52+
- "{{ role_path }}/vars"
4953
tags:
5054
- always
5155

@@ -186,8 +190,8 @@
186190
package:
187191
name: "{{ elastic_distro_packages }}"
188192
state: "{{ elk_package_state | default('present') }}"
189-
install_recommends: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
190-
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
193+
install_recommends: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
194+
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
191195
register: _package_task
192196
until: _package_task is success
193197
retries: 3
@@ -208,7 +212,7 @@
208212
name: java
209213
path: "{{ java_alternatives.stdout.strip() }}"
210214
when:
211-
- (ansible_os_family | lower) == 'debian'
215+
- (ansible_facts['os_family'] | lower) == 'debian'
212216

213217
- name: Ensure service directories exists
214218
file:
@@ -229,7 +233,7 @@
229233
lineinfile:
230234
path: /etc/hosts
231235
regexp: '^{{ item }}'
232-
line: '{{ item }} {{ ansible_hostname }} {{ ansible_fqdn }}'
236+
line: '{{ item }} {{ ansible_facts["hostname"] }} {{ ansible_facts["fqdn"] }}'
233237
owner: root
234238
group: root
235239
mode: 0644

elk_metrics_7x/roles/elastic_filebeat/tasks/main.yml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,26 @@
1414
# limitations under the License.
1515

1616
- name: Gather variables for each operating system
17-
include_vars: "{{ item }}"
18-
with_first_found:
19-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
20-
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
21-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
22-
- "{{ ansible_distribution | lower }}.yml"
23-
- "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml"
24-
- "{{ ansible_os_family | lower }}.yml"
17+
include_vars: "{{ lookup('first_found', params) }}"
18+
vars:
19+
params:
20+
files:
21+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_version'] | lower }}.yml"
22+
- "{{ ansible_facts['distribution'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
23+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_major_version'] | lower }}.yml"
24+
- "{{ ansible_facts['distribution'] | lower }}.yml"
25+
- "{{ ansible_facts['os_family'] | lower }}-{{ ansible_facts['distribution_version'].split('.')[0] }}.yml"
26+
- "{{ ansible_facts['os_family'] | lower }}.yml"
27+
paths:
28+
- "{{ role_path }}/vars"
2529
tags:
2630
- always
2731

2832
- name: Ensure beat is installed
2933
package:
3034
name: "{{ filebeat_distro_packages }}"
3135
state: "{{ elk_package_state | default('present') }}"
32-
update_cache: "{{ (ansible_pkg_mgr == 'apt') | ternary('yes', omit) }}"
36+
update_cache: "{{ (ansible_facts['pkg_mgr'] == 'apt') | ternary('yes', omit) }}"
3337
register: _package_task
3438
until: _package_task is success
3539
retries: 3
@@ -63,11 +67,11 @@
6367

6468
- name: Set dicovery facts to enable Filebeat modules
6569
set_fact:
66-
elasticsearch_enabled: "{{ ((ansible_facts.services['elasticsearch.service'] | default({}) )['state'] | default('')) == 'running' }}"
67-
logstash_enabled: "{{ ((ansible_facts.services['logstash.service'] | default({}) )['state'] | default('')) == 'running' }}"
68-
kibana_enabled: "{{ ((ansible_facts.services['kibana.service'] | default({}) )['state'] | default('')) == 'running' }}"
69-
haproxy_enabled: "{{ ((ansible_facts.services['haproxy.service'] | default({}) )['state'] | default('')) == 'running' }}"
70-
nginx_enabled: "{{ ((ansible_facts.services['nginx.service'] | default({}) )['state'] | default('')) == 'running' }}"
70+
elasticsearch_enabled: "{{ ((ansible_facts.services['elasticsearch.service'] | default({}))['state'] | default('')) == 'running' }}"
71+
logstash_enabled: "{{ ((ansible_facts.services['logstash.service'] | default({}))['state'] | default('')) == 'running' }}"
72+
kibana_enabled: "{{ ((ansible_facts.services['kibana.service'] | default({}))['state'] | default('')) == 'running' }}"
73+
haproxy_enabled: "{{ ((ansible_facts.services['haproxy.service'] | default({}))['state'] | default('')) == 'running' }}"
74+
nginx_enabled: "{{ ((ansible_facts.services['nginx.service'] | default({}))['state'] | default('')) == 'running' }}"
7175

7276
- name: Drop Filebeat conf file
7377
template:

0 commit comments

Comments
 (0)