# -*- mode: yaml; indent-tabs-mode: nil; tab-width: 2; coding: utf-8-unix -*-
---

- name: "toxcore hourly.yml"
  debug:
    msg: "toxcore hourly.yml ansible_virtualization_role {{ansible_virtualization_role|replace('NA', 'host')}}"

# these should test on the host
- block:
  - name: check ifconfig
    # was toxcore_bin.bash
    shell: |
      echo WARN: this maybe vagrant only
      ifconfig eth0 | grep 'inet ' || \
          ifconfig eth0 netmask 255.255.255.0 192.168.122.22
    when:
      - false # this is vagrant only
      - "ansible_virtualization_role|replace('NA', 'host') != 'host'"

  - name: check guest-agent
    # was toxcore_bin.bash
    shell: |
      UNIT=qemu-guest-agent
      S=/etc/init.d/$UNIT
      $S status || {
          retval=$?
          echo WARN: $UNIT not running
          exit 0 # $retval
          }
      exit 0

  when: "ansible_virtualization_role|replace('NA', 'host') != 'host'"

- name: run toxcore_check_modules.bash
  # was toxcore_bin.bash
  shell: |
    bash toxcore_check_modules.bash {{TOXCORE_FEATURES|join(' ')}}
  args:
    chdir: "{{ TOXCORE_VAR_LOCAL }}/bin"
  environment: "{{ shell_proxy_env }}"
  register: toxcore_log_bin
  notify: summary of logs
  # FixMe?
  ignore_errors: true

- name: "run toxcore_hourly.bash"
  environment: "{{ shell_proxy_env }}"
  shell: |
    umask 0027
    echo "INFO: toxcore_log_hourly {{HARDEN_LOG_DIR}}"
    cd {{VAR_LOCAL}}/bin
    toxcore_hourly.bash
  register: toxcore_log_hourly
  notify: summary of logs
  ignore_errors: true
  when:
    - not ansible_check_mode
    - false
