---
- name: configure /etc/hosts
  template:
    src: templates/hosts.j2
    dest: /etc/hosts
- name: configure getaddrinfo
  template:
    src: templates/gai.conf.j2
    dest: /etc/gai.conf
- name: Set correct wwwacct.conf
  template:
    src: templates/wwwacct.j2
    dest: /etc/wwwacct.conf

- name: Install root's cron spool
  template:
    src: templates/var_spool_cron_root.j2
    dest: /var/spool/cron/root
    mode: 0600

- name: Ensure root's cron spool has a newline at the end
  shell: '/bin/echo >> /var/spool/cron/root'

- name: install brand repo
  yum: name=UL_{{ brand }}_repo state=latest
- name: install cpanel_addon_WPC
  shell: 'yum clean all; yum --disablerepo=ul --disableexcludes=all -y install cpanel_addon_WPC'
- name: install brand extras
  yum: name=cpanel_{{ brand }}_extras disablerepo=ul state=latest
  ignore_errors: yes   # webhostbox and others don't have this package
- name: install brand theme
  yum: name=cpanel_{{ brand }}_theme
  ignore_errors: yes   # webhostbox and others don't have this package
- name: install ul_load_stats if correct brand
  yum: name=ul_load_stats state=present
  when: brand is search("bluehost|hostmonster|fastdomain|justhost")

- include: tasks/mysql.yaml
- include: tasks/set_hostname.yaml

- name: cphulkd disable for webhostbox
  command: '/usr/local/cpanel/etc/init/stopcphulkd ; /usr/local/cpanel/bin/cphulk_pam_ctl --disable ; rm -f /var/cpanel/hulkd/enabled'
  when: brand == 'webhostbox'

- name: setup cphulkd when not webhostbox
  command: /usr/local/cpanel/bin/hulkdsetup
  when: brand != 'webhostbox'
- name: whitelist hal
  command: /scripts/cphulkdwhitelist {{ item }}
  with_items:
    - 10.2.0.0/24
    - 10.102.120.0/24
    - 69.195.127.5
  when:  brand != 'webhostbox'

- name: Skip getting started wizard
  file: path=/etc/.whostmgrft state=touch
- name: Skip EULA on first login
  file: path=/var/cpanel/activate/2012-07.v01.EULACPWHM state=touch

# The following are copies from the original cPanel postprov recipe. The 
# utility of some of them is questionable, but we were doing them for some 
# reason and so are preserving them for the moment.
#- name: Check fixpci
#  stat: path=/usr/sec/bin/fixpci
#  register: fixpci
#- name: Execute fixpci
#  command: "/usr/sec/bin/fixpci"
#  when: fixpci.stat.exists and fixpci.stat.mode == "0500"

- name: Add DNS entry
  command: "/scripts/adddns --domain {{ hostname }}"

- name: Allow accesshash access for now
  lineinfile:
    dest: /var/cpanel/cpanel.config
    regexp: '^allow_deprecated_accesshash'
    line: 'allow_deprecated_accesshash=1'

- name: Restart cPanel
  service:
    name: cpanel
    state: restarted

- name: Validate cpanel license
  command: /usr/local/cpanel/cpkeyclt
