Advertisement
Guest User

Untitled

a guest
Jul 9th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 7.99 KB | None | 0 0
  1. - name: ELK Stack
  2.   hosts: elk
  3.   strategy: free
  4.   roles:
  5.     - role: common/base
  6.       tags:
  7.        - os
  8.     - role: common/sshable
  9.       tags:
  10.        - os
  11.     - role: elastic.elasticsearch
  12.       tags:
  13.        - install
  14.         - elasticsearch
  15.   vars:
  16.     es_version: 7.2.0
  17.     es_version_lock: false
  18.     es_data_dirs:
  19.      - /opt/elasticsearch/data
  20.     es_log_dir: /var/log/elasticsearch
  21.     es_heap_size: 1024m
  22.     es_config:
  23.       http.port: 9200
  24.       network.host: 0.0.0.0
  25.       transport.port: 9300
  26.       cluster.name: "logs"
  27.       node.master: true
  28.       node.name: elk01
  29.       cluster.initial_master_nodes: elk01
  30.       # bootstrap.memory_lock: true
  31.     local_net: 172.16.1.0/24
  32.   tasks:
  33.     - name: Change hostname
  34.       hostname:
  35.         name: vmcent76elk
  36.       tags:
  37.        - os
  38.  
  39.     - name: Update /etc/hosts with hostnames
  40.       lineinfile:
  41.         dest: /etc/hosts
  42.         regexp: '^127\.0\.0\.1[ \t]+localhost'
  43.         line: "127.0.0.1 localhost vmcent76elk"
  44.         state: present
  45.       tags:
  46.        - os
  47.    
  48.     # - name: Add Elasticsearch repo
  49.     #   yum_repository:
  50.     #     name: elasticsearch
  51.     #     description: Elasticsearch repository for 7.x packages
  52.     #     gpgcheck: yes
  53.     #     gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
  54.     #     baseurl: https://artifacts.elastic.co/packages/7.x/yum
  55.     #     state: absent
  56.  
  57.     - name: Install logstash
  58.       package:
  59.         name:
  60.          - logstash
  61.           - java-11-openjdk
  62.         state: latest
  63.       tags:
  64.        - install
  65.         - logstash
  66.    
  67.     - name: Install logstash service
  68.       command: /usr/share/logstash/bin/system-install /etc/logstash/startup.options systemd
  69.       args:
  70.         creates: /etc/systemd/system/logstash.service
  71.       tags:
  72.        - install
  73.         - logstash
  74.  
  75.     - name: logstash configuration
  76.       copy:
  77.         content: |
  78.          input {
  79.             beats {
  80.               ssl => false
  81.               host => "::"
  82.               port => 5044
  83.             }
  84.  
  85.             http {
  86.               ssl => false
  87.               host => "::"
  88.               port => 8888
  89.             }
  90.  
  91.             udp {
  92.               host => "::1"
  93.               port => 10514
  94.               codec => "json"
  95.               type => "rsyslog"
  96.             }
  97.           }
  98.  
  99.           output {
  100.             elasticsearch {
  101.               hosts => ["http://localhost:9200"]
  102.               index => "logstash-%{+YYYY.MM.dd}"
  103.               # index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
  104.             }
  105.           }
  106.         dest: /etc/logstash/conf.d/logstash.conf
  107.       tags:
  108.        - logstash
  109.  
  110.     - name: Enable & start logstash
  111.       systemd:
  112.         name: logstash
  113.         enabled: yes
  114.         state: restarted
  115.         daemon_reload: yes
  116.       tags:
  117.        - install
  118.         - logstash
  119.    
  120.     - name: Install kibana
  121.       package:
  122.         name: kibana
  123.         state: latest
  124.       tags:
  125.        - install
  126.         - kibana
  127.    
  128.     - name: Enable & start kibana
  129.       systemd:
  130.         name: kibana
  131.         enabled: yes
  132.         state: restarted
  133.         daemon_reload: yes
  134.       tags:
  135.        - install
  136.         - kibana
  137.    
  138.     - name: Install rsyslog
  139.       package:
  140.         name: rsyslog
  141.         state: latest
  142.       tags:
  143.        - install
  144.         - rsyslog
  145.  
  146.     - name: rsyslog json template config
  147.       copy:
  148.         content: |
  149.          template(name="json-template"
  150.             type="list") {
  151.               constant(value="{")
  152.                 constant(value="\"@timestamp\":\"")     property(name="timereported" dateFormat="rfc3339")
  153.                 constant(value="\",\"@version\":\"1")
  154.                 constant(value="\",\"message\":\"")     property(name="msg" format="json")
  155.                 constant(value="\",\"sysloghost\":\"")  property(name="hostname")
  156.                 constant(value="\",\"severity\":\"")    property(name="syslogseverity-text")
  157.                 constant(value="\",\"facility\":\"")    property(name="syslogfacility-text")
  158.                 constant(value="\",\"programname\":\"") property(name="programname")
  159.                 constant(value="\",\"procid\":\"")      property(name="procid")
  160.               constant(value="\"}\n")
  161.           }
  162.         dest: /etc/rsyslog.d/01-json-template.conf
  163.       tags:
  164.        - rsyslog
  165.    
  166.     - name: rsyslog logstash output config
  167.       copy:
  168.         content: |
  169.           *.* @localhost:10514;json-template
  170.         dest: /etc/rsyslog.d/99-logstash-output.conf
  171.       tags:
  172.        - rsyslog
  173.  
  174.     - name: rsyslog tcp/udp syslog reception
  175.       lineinfile:
  176.         path: /etc/rsyslog.conf
  177.         regex: "#?{{ item | regex_escape() }}"
  178.         line: "{{ item }}"
  179.       with_items:
  180.        - "$ModLoad imudp"
  181.         - "$UDPServerRun 514"
  182.         - "$ModLoad imtcp"
  183.         - "$InputTCPServerRun 514"
  184.       tags:
  185.        - rsyslog
  186.    
  187.     # - name: rsyslog log directory
  188.     #   file:
  189.     #     path: /var/log/rsyslog
  190.     #     state: directory
  191.  
  192.     # - name: rsyslog remote log destination
  193.     #   blockinfile:
  194.     #     path: /etc/rsyslog.conf
  195.     #     insertbefore: "GLOBAL DIRECTIVES"
  196.     #     block: |
  197.    #       # $template RemoteLogs,"/var/log/rsyslog/%HOSTNAME%.log"
  198.     #       # . ?RemoteLogs & ~
  199.  
  200.     - name: selinux allow rsyslog
  201.       seport:
  202.         ports: "514"
  203.         proto: "{{ item }}"
  204.         setype: syslogd_port_t
  205.         state: present
  206.       with_items:
  207.         - tcp
  208.         - udp
  209.       tags:
  210.         - install
  211.         - rsyslog
  212.  
  213.     - name: Enable & start rsyslog
  214.       systemd:
  215.         name: rsyslog
  216.         enabled: yes
  217.         state: restarted
  218.         daemon_reload: yes
  219.       tags:
  220.         - install
  221.         - rsyslog
  222.  
  223.     - name: Install nginx
  224.       package:
  225.         name: nginx
  226.         state: latest
  227.       tags:
  228.         - install
  229.         - nginx
  230.    
  231.     - name: Remove nginx default server
  232.       replace:
  233.         path: /etc/nginx/nginx.conf
  234.         regexp: '(?ms)^\s+server {({[^{}]*}|.*?)+}'
  235.         replace: ''
  236.       tags:
  237.         - nginx
  238.  
  239.     - name: Configure nginx to proxy kibana
  240.       copy:
  241.         content: |
  242.           server {
  243.             listen 80;
  244.             server_name kibana;
  245.  
  246.             error_log   /var/log/nginx/kibana.error.log;
  247.             access_log  /var/log/nginx/kibana.access.log;
  248.  
  249.             location / {
  250.               rewrite ^/(.*) /$1 break;
  251.               proxy_ignore_client_abort on;
  252.               proxy_pass http://localhost:5601;
  253.               proxy_set_header  X-Real-IP  $remote_addr;
  254.               proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  255.               proxy_set_header  Host $http_host;
  256.             }
  257.           }
  258.         dest: /etc/nginx/conf.d/kibana.conf
  259.       tags:
  260.         - nginx
  261.    
  262.     - name: Start nginx service
  263.       systemd:
  264.         name: nginx
  265.         enabled: yes
  266.         state: restarted
  267.       tags:
  268.         - install
  269.         - nginx
  270.  
  271.     - name: selinux allow nginx to network connect
  272.       seboolean:
  273.         name: httpd_can_network_connect
  274.         state: yes
  275.         persistent: yes
  276.       tags:
  277.         - install
  278.         - nginx
  279.  
  280.     - name: Add internal network to firewalld trusted zone
  281.       firewalld:
  282.         source: "{{ local_net }}"
  283.         zone: trusted
  284.         permanent: yes
  285.         immediate: yes
  286.         state: enabled
  287.       tags:
  288.         - os
  289.  
  290.     - name: Open trusted firewall ports
  291.       firewalld:
  292.         port: "{{ item }}"
  293.         zone: trusted
  294.         permanent: yes
  295.         immediate: yes
  296.         state: enabled
  297.       with_items:
  298.         - "80/tcp"
  299.         - "9200/tcp"
  300.       tags:
  301.         - install
  302.         - logstash
  303.         - nginx
  304.    
  305.     - name: Open public firewall ports
  306.       firewalld:
  307.         port: "{{ item }}"
  308.         zone: public
  309.         permanent: yes
  310.         immediate: yes
  311.         state: enabled
  312.       with_items:
  313.         - "514/tcp"
  314.         - "514/udp"
  315.         - "8888/tcp"
  316.       tags:
  317.         - install
  318.         - rsyslog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement