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

- name: Sync Flume Config Files
  synchronize:  # need input password in command line if ssh key is none.
    src: conf
    dest: /opt/flume/apache-flume-1.8.0-bin
    delete: yes
  tags: flume_conf, flume_stop

- name: Stop All Flume Agent
  shell: ps -ef |grep [f]lume |awk '{print $2}'|xargs kill; echo "Stop All Agent Done."
  tags: flume_conf, flume_stop


- name: Clean Local Data
  file: 
    path: /data/flume/data
    state: absent
  tags: flume_stop, flume_conf

- name: Start All Flume Agent
  shell: "{{ item }}"
  with_items:
    - "nohup bin/flume-ng agent --conf conf --conf-file conf/nginx.access.conf --name agent01 -Dflume.root.logger=INFO,console >/dev/null 2>&1 &"
    - "nohup bin/flume-ng agent --conf conf --conf-file conf/backend.log.conf --name agent05 -Dflume.root.logger=INFO,console >/dev/null 2>&1 &"
  args:
    chdir: /opt/flume/apache-flume-1.8.0-bin
  tags: flume_conf

