---
# install dd-agent from source

- name: install packages
  apt:
    state: installed
    package: "{{ item }}"
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - python-psutil

- shell: DD_API_KEY=ca0faf176c4aedd4f547ed7cf85615eb DD_SKIP_INTEGRATIONS=1 DD_START_AGENT=0 sh -c "$(curl -L https://raw.githubusercontent.com/DataDog/dd-agent/master/packaging/datadog-agent/source/setup_agent.sh)"
  args:
    creates: "/root/.datadog-agent/bin/agent"

- name: add agent line to rc.local
  lineinfile:
    dest: /etc/rc.local
    regexp: '^nohup sh /root/.datadog-agent/bin/agent &'
    line: 'nohup sh /root/.datadog-agent/bin/agent &'
    insertbefore: "^exit 0"

- name: start agent
  shell: /root/.datadog-agent/bin/agent start
