---
- name: Add SSH authorized key for synchronize Moudle
  authorized_key:
    user: root
    state: present
    key: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
  tags: logstash_conf

- name: Sync Logstash Config Files
  synchronize:  # need input password in command line if ssh key is none.
    src: "{{ item }}"
    dest: /opt/logstash/logstash-6.0.0
    delete: yes
  with_items:
    - "config"
    - "patterns"   
  tags: logstash_conf, logstash_stop

- name: Stop All Flume Agent
  shell: ps -ef |grep [l]ogstash |grep nginx_access.conf |awk '{print $2}'|xargs kill; echo "Stop All Agent Done."
  tags: logstash_conf, logstash_stop


#- name: Clean Local Data
#  file: 
#    path: /data/logstash/data
#    state: absent
#  tags: logstash_stop, logstash_conf

- name: Start All Logstash Agent
  shell: "{{ item }}"
  with_items:
    - "nohup bin/logstash -f config/nginx_access.conf --config.reload.automatic >/dev/null 2>&1 &"
#    - "nohup bin/logstash-ng agent --conf conf --conf-file conf/backend.log.conf --name agent05 -Dlogstash.root.logger=INFO,console >/dev/null 2>&1 &"
  args:
    chdir: /opt/logstash/logstash-6.0.0
  tags: logstash_conf

