---
- name: install supervisor
  pip:
    name: supervisor

- name: update setuptools 
  pip:
   name: setuptools
   extra_args: -U

- name: install php supervisor config
  template: src=supervisord.conf dest=/etc/supervisord.conf
  vars: 
    supervisor_group: "{{ supervior_cassandra_vars }}"
  #include_vars: supervisor.yml    
  when: inventory_hostname in groups['cassandra']

- name: create supervisord log path
  file:
    path: /opt/supervisor_log
    state: directory
    mode: 0755

- name: install supervisord service with EL6  
  copy: src=supervisord.sh dest=/etc/init.d/supervisord.sh owner=root group=root mode=0755
  when: ansible_distribution == 'CentOS' and ansible_lsb.major_release|int < 7

- name: supervisord service start with EL6
  shell: /etc/init.d/supervisord.sh restart
  when: ansible_distribution == 'CentOS' and ansible_lsb.major_release|int < 7

- name: install supervisord service with EL7
  copy: src=supervisord.service dest=/usr/lib/systemd/system/supervisord.service owner=root group=root mode=0644
  when: ansible_distribution == 'CentOS' and ansible_lsb.major_release|int > 6

- name: supervisord service start with EL7
  shell: systemctl enable supervisord;systemctl restart supervisord
  when: ansible_distribution == 'CentOS' and ansible_lsb.major_release|int > 6


#- name: install supervisord service with Ubuntu14
#  copy: src=supervisord.sh dest=/etc/init.d/supervisord.sh owner=root group=root mode=0755
#  when: ansible_distribution == 'Ubuntu' and ansible_lsb.major_release|int > 13

- name: supervisord service start with Ubuntu14
  shell: /usr/local/bin/supervisord -c /etc/supervisord.conf
  when: ansible_distribution == 'Ubuntu' and ansible_lsb.major_release|int > 13
