---

- name: Configure agent
  become: yes
  template:
    src: datadog.conf.j2
    dest: /etc/dd-agent/datadog.conf
  notify:
    - restart datadog

- name: Enable any integrations
  become: yes
  template:
    src: "conf.d/{{ item.key }}.yaml.j2"
    dest: "/etc/dd-agent/conf.d/{{ item.key }}.yaml"
    owner: dd-agent
  with_dict: "{{ datadog.integrations }}"
  notify:
    - restart datadog

- name: Enable and start agent if autostart enabled
  become: yes
  service:
    enabled: true
    name: datadog-agent
    state: started
  when: datadog.autostart_agent

---

- name: Configure agent
  become: yes
  template:
    src: datadog.conf.j2
    dest: /etc/dd-agent/datadog.conf
  notify:
    - restart datadog

- name: Enable any integrations
  become: yes
  template:
    src: "conf.d/{{ item.key }}.yaml.j2"
    dest: "/etc/dd-agent/conf.d/{{ item.key }}.yaml"
    owner: dd-agent
  with_dict: "{{ datadog.integrations }}"
  notify:
    - restart datadog

- name: Enable and start agent if autostart enabled
  become: yes
  service:
    enabled: true
    name: datadog-agent
    state: started
  when: datadog.autostart_agent

- name: Change Datadog Upstart Runlevel - Create Symlinks
  become: yes
  file:
    src: "/etc/init.d/datadog-agent"
    dest: "{{ item }}"
    owner: root
    group: root
    state: link
  with_items:
    - /etc/rc0.d/K05datadog-agent
    - /etc/rc6.d/K05datadog-agent

- name: Change Datadog Upstart Runlevel - Delete old defunct Symlinks
  become: yes
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - /etc/rc0.d/K20datadog-agent
    - /etc/rc6.d/K20datadog-agent

Stop Datadog at the beginning of shutdown process
[GITHUB-3] Stop Datadog at the beginning of shutdown process

This change is to prevent false positive Datadog alerts during instance termination.
