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. # This will work on a new install.
# If any changes are needed to the cluster name on an existing install add another function # If any changes are needed to the cluster name on an existing install add another function
- name: Config - cluster.name 'elastic-DMI01' - name: Config - cluster.name 'logging-dev'
become: true become: true
lineinfile: lineinfile:
path: /etc/elasticsearch/elasticsearch.yml path: /etc/elasticsearch/elasticsearch.yml
regex: '^cluster.name' regex: '^cluster.name'
insertafter: '#cluster.name: my-application' insertafter: '#cluster.name: my-application'
line: 'cluster.name: elastic-DMI01' line: 'cluster.name: logging-dev'
backup: yes backup: yes
# We define the name of the host we are working on # We define the name of the host we are working on
- name: Config - node.name - name: Config - node.name
become: true become: true
lineinfile: lineinfile:
path: /etc/elasticsearch/elasticsearch.yml path: /etc/elasticsearch/elasticsearch.yml
regex: '^node.name' regex: '^node.name'
insertafter: '#node.name: node-1' insertafter: '#node.name: node-1'
line: "node.name: {{ ansible_eno1.ipv4.address }}" 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 # Allow 9200 so we can access it over the network
- name: Allow port 9200 though UFW - name: Allow port 9200 though UFW
become: true become: true
ufw: ufw:
rule: allow rule: allow
port: 9200 port: 9200
#name: ElasticSearch #name: ElasticSearch
- name: Allow port 9300 though UFW
become: true
ufw:
rule: allow
port: 9300
- name: Service reload daemon - name: Service reload daemon
become: true become: true
systemd: systemd:
daemon_reload: yes daemon_reload: yes
- name: systemd - enable ElasticSearch on startup - name: systemd - enable ElasticSearch on startup
become: true become: true
systemd: systemd:
name: elasticsearch name: elasticsearch
enabled: yes enabled: yes
- name: systemd - restart ElasticSearch service - name: systemd - restart ElasticSearch service
become: true become: true
systemd: systemd:
name: elasticsearch name: elasticsearch
state: restarted state: restarted

View File

@ -7,6 +7,15 @@
insertafter: '#host: "localhost:5601"' insertafter: '#host: "localhost:5601"'
line: 'host: "dm-nagios.local: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 - name: systemd - daemon reload
become: true become: true
systemd: systemd:

View File

@ -17,13 +17,22 @@
insertafter: '#server.host' insertafter: '#server.host'
line: 'server.host: {{ ansible_eno1.ipv4.address }}' 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 - name: Config - elasticsearch.hosts
become: true become: true
lineinfile: lineinfile:
path: /etc/kibana/kibana.yml path: /etc/kibana/kibana.yml
regex: '^elasticsearch.hosts' regex: '^elasticsearch.hosts'
insertafter: '#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 - name: Allow port 5601
become: true become: true

View File

@ -5,27 +5,33 @@
become: true become: true
lineinfile: lineinfile:
path: /etc/metricbeat/metricbeat.yml path: /etc/metricbeat/metricbeat.yml
regex: '^host: "dm-nagios.local:5601"' regexp: 'host: "localhost:5601"'
insertafter: '#host: "localhost:5601"' #insertafter: '#host: "localhost:5601"'
line: 'host: "dm-nagios.local:5601"' line: ' host: "192.168.0.173:5601"'
state: present
#- name: config where to send information backrefs: yes
#- name: Remove builtin elasticsearch host config
# become: true
# replace:
#dest: /etc/metricbeat/metricbeat.yml
#regexp: '^hosts: ["localhost:9200"]'
#replace: '#hosts: ["localhost:9200"]'
- name: define elasticsearch host - name: define elasticsearch host
become: true become: true
lineinfile: lineinfile:
path: /etc/metricbeat/metricbeat.yml path: /etc/metricbeat/metricbeat.yml
regex: '^hosts: ["localhost:9200"]' regexp: 'hosts: \["localhost:9200"\]'
insertafter: 'hosts: ["localhost:9200"]' #insertafter: '#hosts: ["localhost:9200"]'
line: 'hosts: ["dm-nagios.local: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 - name: systemd - daemon reload
become: true become: true

View File

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