- name: Install {{appname}}
  include_tasks: tasks/install_without_docker.yml
  vars:
     app: "bt"

- name: install expect
  yum:
    name: expect
    state: latest
  when: ansible_os_family == "RedHat"

- name: install expect for ubuntu
  apt:
    name: expect
    state: latest
  when: ansible_os_family == "Debian"

##------ download script start ------ ###
- name: download Chinese install.sh for {{ansible_os_family}}
  get_url:
    url: "{{bt_download_url[ansible_os_family].zh}}"
    dest: /root/install.sh
    mode: '0644'
  when: bt_language == 'zh'

- name: download English install.sh for {{ansible_os_family}}
  get_url:
    url: "{{bt_download_url[ansible_os_family].en}}"
    dest: /root/install.sh
    mode: '0644'
  when: bt_language == 'en'

##------ download script end ------ ###

- name: copy bt install script
  copy: src=bt.exp  dest=/root/bt.exp  mode=0644

- name: copy change username & password script for English
  copy: src=en-{{item}}  dest=/root/{{item}}  mode=0644
  with_items: "{{bt_filelist}}"
  when: bt_language == 'en'

- name: copy change username & password script for Chinese
  copy: src=zh-{{item}}  dest=/root/{{item}}  mode=0644
  with_items: "{{bt_filelist}}"
  when: bt_language == 'zh'

# this step may get error most of times
- name: install bt, waiting for 5-10 mins
  shell: echo y | bash /root/install.sh

- name: change username & password
  shell: expect /root/{{item}}
  with_items: "{{bt_filelist}}"
  ignore_errors: yes
  
- name: remove extra files 
  shell: |
    cp /root/password.exp /data/apps/bt/password.exp
    rm -f  /root/*.exp

- name: close bt-panel security login
  file:
    path: /www/server/panel/data/admin_path.pl
    state: absent

- name: Create log folder because bt is before the common
  file:
    path: '/data/{{item}}'
    state: directory
    recurse: yes
    mode: '0755'
  with_items:
    - logs

- name: Check BT Version
  shell: sudo echo "bt version:" $(curl -Ss http://www.bt.cn/api/panel/get_version) |sudo  tee -a /data/logs/install_version.txt
