Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 3rd party integrations #291

Merged
merged 5 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,16 @@ Available actions:
version: <VERSION_TO_INSTALL>
```

To install third party integrations, set `third_party` to true:

```yml
datadog_integration:
<INTEGRATION_NAME>:
action: <ACTION>
version: <VERSION_TO_INSTALL>
third_party: true
```

##### Example

This example installs version `1.11.0` of the ElasticSearch integration and removes the `postgres` integration.
Expand Down
2 changes: 1 addition & 1 deletion manual_tests/inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[test_host]
127.0.0.1 ansible_ssh_host=localhost ansible_ssh_user=vagrant ansible_ssh_port=2200 ansible_ssh_private_key_file=./ansible-datadog/tests/.vagrant/machines/default/virtualbox/private_key
127.0.0.1 ansible_ssh_host=localhost ansible_ssh_user=vagrant ansible_ssh_port=2222 ansible_ssh_private_key_file=./ansible-datadog/manual_tests/.vagrant/machines/default/virtualbox/private_key
5 changes: 5 additions & 0 deletions manual_tests/test_7_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
env: dev
trace.concentrator:
extra_aggregators: version
datadog_integration:
datadog-aqua:
action: 'install'
version: '1.0.0'
third_party: true
datadog_checks:
process:
init_config:
Expand Down
9 changes: 2 additions & 7 deletions tasks/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,14 @@
# Install integrations

- name: Install pinned version of integrations (Unix)
command:
argv:
- "{{ datadog_agent_binary_path }}"
- integration
- install
- "{{ item.key }}=={{ item.value.version }}"
command: "{{ datadog_agent_binary_path }} integration install {% if 'third_party' in item.value and item.value.third_party %}--third-party{% endif %} {{ item.key }}=={{ item.value.version }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Saltstack, I'm doing a strict comparison for item.value.third_party: https://github.com/DataDog/datadog-formula/blob/4a82ce48cc95b7acada75633e7227811798e2a53/datadog/config.sls#L64

because otherwise any truthy value works (eg. any non-empty string). Is that also the case here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also the case here, I can make it explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I didn't find a way to define intermediate variables, so the condition is in the middle of the string. If there's a better way to write this in Ansible let me know :)

Copy link
Contributor

@KSerrania KSerrania Aug 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could maybe do something like:

- name: Install pinned version of integrations (Unix)
  command: "{{ datadog_agent_binary_path }} integration install (( third_party }}{{ item.key }}=={{ item.value.version }}"
  become: yes
  become_user: "{{ integration_command_user }}"
  vars:
    third_party: "{% if 'third_party' in item.value and item.value.third_party == true %}--third-party {% endif %}"
  loop: "{{ datadog_integration|dict2items }}"
  when: item.value.action == "install" and ansible_os_family != "Windows"

We're already using this syntax here:

- name: Parse Agent version
set_fact:
agent_version: "{{ datadog_agent_version | regex_search(regexp, '\\g<epoch>', '\\g<major>', '\\g<minor>', '\\g<bugfix>', '\\g<suffix>', '\\g<release>') }}"
vars:
regexp: '(?:(?P<epoch>[0-9]+):)?(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<bugfix>[0-9]+)(?P<suffix>(?:~|-)[^0-9\s-]+[^-\s]*)?(?:-(?P<release>[0-9]+))?'

However, that assumes that vars works correctly with loop (ie. that item is correctly defined in vars), which I haven't tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works and I find it slightly more readable, so I've changed it 👍

become: yes
become_user: "{{ integration_command_user }}"
loop: "{{ datadog_integration|dict2items }}"
when: item.value.action == "install" and ansible_os_family != "Windows"

- name: Install pinned version of integrations (Windows)
win_command: "\"{{ datadog_agent_binary_path }}\" integration install {{ item.key }}=={{ item.value.version }}"
win_command: "\"{{ datadog_agent_binary_path }}\" integration install {% if 'third_party' in item.value and item.value.third_party %}--third-party{% endif %} {{ item.key }}=={{ item.value.version }}"
become: yes
become_user: "{{ integration_command_user }}"
loop: "{{ datadog_integration|dict2items }}"
Expand Down