After trying to go down the path of editing the configs with inline I am going to change over to a template file and see if I can get that to work better for me.  At least Elastic will now let me hit the REST.
This commit is contained in:
James Tombleson 2019-04-23 12:21:00 -07:00
parent 195f730c30
commit 3f49a5fe88
8 changed files with 165 additions and 53 deletions

View File

@ -1,44 +1,98 @@
# This will work on a new install.
# If any changes are needed to the cluster name on an existing install add another function
- name: Config - cluster.name 'elastic-DMI01'
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regex: '^cluster.name'
insertafter: '#cluster.name: my-application'
line: 'cluster.name: elastic-DMI01'
backup: yes
- name: Config - cluster.name 'logging-dev'
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regex: '^cluster.name'
insertafter: '#cluster.name: my-application'
line: 'cluster.name: logging-dev'
backup: yes
# We define the name of the host we are working on
- name: Config - node.name
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regex: '^node.name'
insertafter: '#node.name: node-1'
line: "node.name: {{ ansible_eno1.ipv4.address }}"
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regex: '^node.name'
insertafter: '#node.name: node-1'
line: "node.name: dev-data-01"
- name: Config - network.host
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: 'network.host:'
insertafter: '#network.host:'
line: 'network.host: {{ ansible_eno1.ipv4.address }}'
- name: Config - transport.host
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: 'transort.host:'
#insertafter: 'http.port: 9200'
line: 'transport.host: localhost'
state: present
#backrefs: yes
- name: Config - transport.tcp.port
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: 'transport.tcp.port:'
#insertafter: 'transport.host: localhost'
line: 'transport.tcp.port: 9300'
state: present
backrefs: yes
- name: Config - node.master
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: 'node.master:'
insertafter: 'node.name:'
line: 'node.master: true'
state: present
backrefs: yes
- name: Config - node.data
become: true
lineinfile:
path: /etc/elasticsearch/elasticsearch.yml
regexp: 'node.data:'
insertafter: 'node.master:'
line: 'node.data: true'
state: present
backrefs: yes
# Allow 9200 so we can access it over the network
- name: Allow port 9200 though UFW
become: true
ufw:
rule: allow
port: 9200
#name: ElasticSearch
become: true
ufw:
rule: allow
port: 9200
#name: ElasticSearch
- name: Allow port 9300 though UFW
become: true
ufw:
rule: allow
port: 9300
- name: Service reload daemon
become: true
systemd:
daemon_reload: yes
become: true
systemd:
daemon_reload: yes
- name: systemd - enable ElasticSearch on startup
become: true
systemd:
name: elasticsearch
enabled: yes
become: true
systemd:
name: elasticsearch
enabled: yes
- name: systemd - restart ElasticSearch service
become: true
systemd:
name: elasticsearch
state: restarted
become: true
systemd:
name: elasticsearch
state: restarted

View File

@ -7,6 +7,15 @@
insertafter: '#host: "localhost:5601"'
line: 'host: "dm-nagios.local:5601"'
- name: define elasticsearch host
become: true
lineinfile:
path: /etc/heartbeat/heartbeat.yml
regexp: 'hosts: \["localhost:9200"\]'
line: ' host: ["dm-nagios.local:9200"]'
state: present
backrefs: yes
- name: systemd - daemon reload
become: true
systemd:

View File

@ -17,13 +17,22 @@
insertafter: '#server.host'
line: 'server.host: {{ ansible_eno1.ipv4.address }}'
- name: Config - server.name
become: true
lineinfile:
path: /etc/kibana/kibana.yml
regexp: 'server.name:'
insertafter: '#server.name: "your-hostname"'
line: 'server.name: {{ ansible_hostname }}'
- name: Config - elasticsearch.hosts
become: true
lineinfile:
path: /etc/kibana/kibana.yml
regex: '^elasticsearch.hosts'
insertafter: '#elasticsearch.hosts:'
line: 'elasticsearch.hosts: ["http://localhost:9200"]'
#line: 'elasticsearch.hosts: ["http://{{ ansible_eno1.ipv4.address }}:9200"]'
line: 'elasticsearch.hosts: ["https://localhost:9200"]'
- name: Allow port 5601
become: true

View File

@ -5,27 +5,33 @@
become: true
lineinfile:
path: /etc/metricbeat/metricbeat.yml
regex: '^host: "dm-nagios.local:5601"'
insertafter: '#host: "localhost:5601"'
line: 'host: "dm-nagios.local:5601"'
#- name: config where to send information
#- name: Remove builtin elasticsearch host config
# become: true
# replace:
#dest: /etc/metricbeat/metricbeat.yml
#regexp: '^hosts: ["localhost:9200"]'
#replace: '#hosts: ["localhost:9200"]'
regexp: 'host: "localhost:5601"'
#insertafter: '#host: "localhost:5601"'
line: ' host: "192.168.0.173:5601"'
state: present
backrefs: yes
- name: define elasticsearch host
become: true
lineinfile:
path: /etc/metricbeat/metricbeat.yml
regex: '^hosts: ["localhost:9200"]'
insertafter: 'hosts: ["localhost:9200"]'
line: 'hosts: ["dm-nagios.local:9200"]'
regexp: 'hosts: \["localhost:9200"\]'
#insertafter: '#hosts: ["localhost:9200"]'
line: ' hosts: ["192.168.0.173:9200"]'
state: present
backrefs: yes
- name: enable system module
become: true
shell: metricbeat modules enable system
- name: run metricbeat setup
become: true
shell: metricbeat setup
- name: start metricbeat service
become: true
shell: metricbeat service metricbeat start
- name: systemd - daemon reload
become: true

View File

@ -2,19 +2,19 @@
# This will install all the client parts needed for elastic to monitor client computers
- name: Install elastic client programs
hosts: linux
hosts: elasticClients
tasks:
- name: Install elastic repo
include: install-repo.yml
- name: Install elastic heartbeat
become: true
apt:
name: heartbeat-elastic
#- name: Install elastic heartbeat
#become: true
#apt:
#name: heartbeat-elastic
- name: Configure elastic heartbeazt
include: config-heartbeat.yml
#- name: Configure elastic heartbeat
#include: config-heartbeat.yml
- name: Install elastic metricbeat
become: true

View File

@ -0,0 +1,15 @@
---
- name: update metricbeat
hosts: linux
tasks:
- name: define elasticsearch hosts
become: true
lineinfile:
path: /etc/metricbeat/metricbeat.yml
regexp: 'hosts: \["localhost:9200"\]'
#insertafter: 'hosts: \["localhost:9200"\]'
line: ' hosts: ["dm-nagios.local:9200"]'
state: present
backrefs: yes

5
playbook/templateTest.j2 Normal file
View File

@ -0,0 +1,5 @@
{{ var01 }}
{{ var02 }}

14
playbook/templateTest.yml Normal file
View File

@ -0,0 +1,14 @@
- name: TemplateTest
hosts: elasticClients
vars:
var01: 'Hello world'
var02: "Why did I start at 1?"
tasks:
- name: ansible template
template:
src: templateTest.j2
dest: /tmp/templatetest.txt