From 3f49a5fe88d8ea6447167fc61224226852642df6 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Tue, 23 Apr 2019 12:21:00 -0700 Subject: [PATCH] -sigh- 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. --- .../linux/elastic/config-elasticsearch.yml | 114 +++++++++++++----- playbook/linux/elastic/config-heartbeat.yml | 9 ++ playbook/linux/elastic/config-kibana.yml | 11 +- playbook/linux/elastic/config-metricbeat.yml | 36 +++--- playbook/linux/elastic/install-client.yml | 14 +-- playbook/linux/elastic/t.yml | 15 +++ playbook/templateTest.j2 | 5 + playbook/templateTest.yml | 14 +++ 8 files changed, 165 insertions(+), 53 deletions(-) create mode 100644 playbook/linux/elastic/t.yml create mode 100644 playbook/templateTest.j2 create mode 100644 playbook/templateTest.yml diff --git a/playbook/linux/elastic/config-elasticsearch.yml b/playbook/linux/elastic/config-elasticsearch.yml index 019b899..c19978c 100644 --- a/playbook/linux/elastic/config-elasticsearch.yml +++ b/playbook/linux/elastic/config-elasticsearch.yml @@ -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 diff --git a/playbook/linux/elastic/config-heartbeat.yml b/playbook/linux/elastic/config-heartbeat.yml index ad2dacd..a7ea73d 100644 --- a/playbook/linux/elastic/config-heartbeat.yml +++ b/playbook/linux/elastic/config-heartbeat.yml @@ -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: diff --git a/playbook/linux/elastic/config-kibana.yml b/playbook/linux/elastic/config-kibana.yml index 1152ec6..d7513d0 100644 --- a/playbook/linux/elastic/config-kibana.yml +++ b/playbook/linux/elastic/config-kibana.yml @@ -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 diff --git a/playbook/linux/elastic/config-metricbeat.yml b/playbook/linux/elastic/config-metricbeat.yml index 90fed44..e9b6386 100644 --- a/playbook/linux/elastic/config-metricbeat.yml +++ b/playbook/linux/elastic/config-metricbeat.yml @@ -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 diff --git a/playbook/linux/elastic/install-client.yml b/playbook/linux/elastic/install-client.yml index 9573703..0072b57 100644 --- a/playbook/linux/elastic/install-client.yml +++ b/playbook/linux/elastic/install-client.yml @@ -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 diff --git a/playbook/linux/elastic/t.yml b/playbook/linux/elastic/t.yml new file mode 100644 index 0000000..c85096b --- /dev/null +++ b/playbook/linux/elastic/t.yml @@ -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 diff --git a/playbook/templateTest.j2 b/playbook/templateTest.j2 new file mode 100644 index 0000000..1cba573 --- /dev/null +++ b/playbook/templateTest.j2 @@ -0,0 +1,5 @@ + + +{{ var01 }} + +{{ var02 }} diff --git a/playbook/templateTest.yml b/playbook/templateTest.yml new file mode 100644 index 0000000..cf0b1c8 --- /dev/null +++ b/playbook/templateTest.yml @@ -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