Skip to content

Commit

Permalink
Adding Agent6 (beta) support on debianoids (#81)
Browse files Browse the repository at this point in the history
Flipping the attribute 'datadog_agent6' to true installs the agent6
instead of the agent5. Switching it back to false would reverse the
operation as long as the agent 5 version is pinned.
  • Loading branch information
hush-hush authored and olivielpeau committed Oct 27, 2017
1 parent 6b7583d commit 3ba579e
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 34 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,27 @@ Role Variables
- `datadog_apt_repo` - Override default Datadog `apt` repository
- `datadog_apt_key_url` - Override default url to Datadog `apt` key
- `datadog_apt_key_url_new` - Override default url to the new Datadog `apt` key (in the near future the `apt` repo will have to be checked against this new key instead of the current key)
- `datadog_allow_agent_downgrade` - Set to `yes` to allow agent downgrades on apt-based platforms (use with caution, see `defaults/main.yml` for details)
- `datadog_agent_allow_downgrade` - Set to `yes` to allow agent downgrades on apt-based platforms (use with caution, see `defaults/main.yml` for details)

Agent 6 (beta)
--------------

To upgrade or install agent6, you need to:

- set `datadog_agent6` to true
- either set `datadog_agent_version` to an existing agent6 version
(recommended) or leave it empty to always install the latest version.

To downgrade from agent6 to agent5, you need to:

- set `datadog_agent6` to false
- pin `datadog_agent_version` to an existing agent5 version
- set `datadog_agent_allow_downgrade` to yes

Variables:

- `datadog_agent6` - install an agent6 instead of agent5 (default to `false`)
- `datadog_agent6_apt_repo` - Override default Datadog `apt` repository for agent6

Dependencies
------------
Expand Down
26 changes: 26 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,29 @@ datadog_agent_version: ""
# Set this to `yes` to allow agent downgrades on apt-based platforms.
# Internally, this uses `apt-get`'s `--force-yes` option. Use with caution.
datadog_agent_allow_downgrade: no

########################################################################
### Beta-Agent6-only attributes, experimental ###
### These attributes are not part of the stable API of the role ###
### Subject to breaking changes between bugfix/minor versions ###
### Only works on debianoids for now ###

# Set to true to install an agent6 instead of agent5.
#
# To upgrade from agent5 to agent6, you need to:
# * set 'datadog_agent6' to true, and
# * either set 'datadog_agent_version' to an existing agent6 version
# (recommended) or leave it empty to always install the latest version.
#
# To downgrade from agent6 to agent5, you need to:
# * 'datadog_set agent6' to false, and
# * pin 'datadog_agent_version' to an existing agent5 version
# * set 'datadog_agent_allow_downgrade' to yes
datadog_agent6: no

# beta APT repo where datadog-agent v6 packages are available
datadog_agent6_apt_repo: "deb http://apt.datadoghq.com beta main"

### End of Beta-Agent6-only experimental attributes ###
########################################################################

34 changes: 34 additions & 0 deletions tasks/agent5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
- name: Create main Datadog agent configuration file
template:
src: datadog.conf.j2
dest: /etc/dd-agent/datadog.conf
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
notify: restart datadog-agent

# DEPRECATED: Remove specific handling of the process check for next major release
- name: Add process check configuration
template: src=process.yaml.j2 dest=/etc/dd-agent/conf.d/process.yaml
when: datadog_process_checks is defined
notify: restart datadog-agent

- debug: 'msg="[DEPRECATION NOTICE] Using `datadog_process_checks` is deprecated, use `process` under `datadog_checks` instead"'
when: datadog_process_checks is defined

- name: Ensure datadog-agent is running
service: name=datadog-agent state=started enabled=yes
when: datadog_enabled

- name: Ensure datadog-agent is not running
service: name=datadog-agent state=stopped enabled=no
when: not datadog_enabled

- name: Create a configuration file for each Datadog check
template:
src: checks.yaml.j2
dest: /etc/dd-agent/conf.d/{{ item }}.yaml
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
with_items: '{{ datadog_checks|list }}'
notify: restart datadog-agent
44 changes: 44 additions & 0 deletions tasks/agent6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Create main Datadog agant yaml configuration file (beta)
template:
src: datadog.yaml.j2
dest: /etc/datadog-agent/datadog.yaml
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
notify: restart datadog-agent

- debug: 'msg="Using deprecated `datadog_process_checks` is no longer supported in agent6, use `process` under `datadog_checks` instead"'
when: datadog_process_checks is defined

- name: Create a configuration file for each Datadog check
template:
src: checks.yaml.j2
dest: "/etc/datadog-agent/conf.d/{{ item }}.yaml"
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
with_items: '{{ datadog_checks|list }}'
notify: restart datadog-agent

- name: Create trace agent configuration file
template:
src: datadog.conf.j2
dest: /etc/datadog-agent/trace-agent.conf
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
notify: restart datadog-agent

- name: Create process agent configuration file
template:
src: datadog.conf.j2
dest: /etc/datadog-agent/process-agent.conf
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
notify: restart datadog-agent

- name: Ensure datadog-agent is running
service: name=datadog-agent state=started enabled=yes
when: datadog_enabled

- name: Ensure datadog-agent is not running
service: name=datadog-agent state=stopped enabled=no
when: not datadog_enabled
36 changes: 4 additions & 32 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,8 @@
- include: pkg-redhat.yml
when: ansible_os_family == "RedHat"

- name: Create main Datadog agent configuration file
template:
src: datadog.conf.j2
dest: /etc/dd-agent/datadog.conf
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
notify: restart datadog-agent
- include: agent5.yml
when: not datadog_agent6

# DEPRECATED: Remove specific handling of the process check for next major release
- name: Add process check configuration
template: src=process.yaml.j2 dest=/etc/dd-agent/conf.d/process.yaml
when: datadog_process_checks is defined
notify: restart datadog-agent

- debug: 'msg="[DEPRECATION NOTICE] Using `datadog_process_checks` is deprecated, use `process` under `datadog_checks` instead"'
when: datadog_process_checks is defined

- name: Ensure datadog-agent is running
service: name=datadog-agent state=started enabled=yes
when: datadog_enabled

- name: Ensure datadog-agent is not running
service: name=datadog-agent state=stopped enabled=no
when: not datadog_enabled

- name: Create a configuration file for each Datadog check
template:
src: checks.yaml.j2
dest: /etc/dd-agent/conf.d/{{ item }}.yaml
owner: '{{ datadog_user }}'
group: '{{ datadog_group }}'
with_items: '{{ datadog_checks|list }}'
notify: restart datadog-agent
- include: agent6.yml
when: datadog_agent6
11 changes: 10 additions & 1 deletion tasks/pkg-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
when: datadog_apt_key_url is defined

- name: Ensure Datadog repository is up-to-date
apt_repository: repo='{{ datadog_apt_repo }}' state=present update_cache=yes
apt_repository:
repo: "{{ datadog_apt_repo }}"
state: "{% if datadog_agent6 %}absent{% else %}present{% endif %}"
update_cache: yes

- name: Ensure Datadog repository is up-to-date (beta)
apt_repository:
repo: "{{ datadog_agent6_apt_repo }}"
state: "{% if datadog_agent6 %}present{% else %}absent{% endif %}"
update_cache: yes

- name: Ensure pinned version of Datadog agent is installed
apt:
Expand Down
11 changes: 11 additions & 0 deletions templates/datadog.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Managed by Ansible

{% if datadog_config["dd_url"] is not defined -%}
dd_url: {{ datadog_url | default('https://app.datadoghq.com') }}
{% endif %}

{% if datadog_config["api_key"] is not defined -%}
api_key: {{ datadog_api_key | default('youshouldsetthis') }}
{% endif %}

{{ datadog_config | to_nice_yaml }}

0 comments on commit 3ba579e

Please sign in to comment.