Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into kserrania/agent7-su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
KSerrania committed Dec 12, 2019
2 parents 4d99593 + f31ab63 commit 102d6ba
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 13 deletions.
71 changes: 70 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,29 @@ To override the default behavior, set the `datadog_windows_download_url` variabl
| `datadog_additional_groups` | Comma separated list of additional groups for the `datadog_user`. Linux only. |
| `datadog_windows_ddagentuser_name` | Name of windows user to create/use, in the format `<domain>\<user>`. Windows only. |
| `datadog_windows_ddagentuser_password` | Password to use to create the user, and/or register the service. Windows only. |
## datadog_agent_version variable

Starting with version 3 of this role, when the `datadog_agent_version` variable is used to pin a specific Agent version, the role will derive per-OS version names to comply with the version naming schemes of the operating systems we support (eg. `1:7.16.0-1` for Debian- and SUSE- based, `7.16.0-1` for Redhat-based and `7.16.0` for Windows).

This makes it possible to target hosts running different operating systems in the same Ansible run.

For instance, you can now provide:

```yaml
datadog_agent_version: 7.16.0
```
and the role will install `1:7.16.0-1` on Debian- and SUSE-based systems, `7.16.0-1` on Redhat-based systems, and `7.16.0` on Windows
(if not provided, the role uses `1` as the epoch, and `1` as the release number).

Alternatively, you can provide:

```yaml
datadog_agent_version: 1:7.16.0-1
```

and the role will install `1:7.16.0-1` on Debian- and SUSE-based systems, `7.16.0-1` on Redhat-based systems, and `7.16.0` on Windows.


## Agent 5 (older version)

Expand Down Expand Up @@ -240,7 +263,7 @@ Sending data to Datadog US (default) and configuring a few checks.
```yml
- hosts: servers
roles:
- { role: Datadog.datadog, become: yes } # remove the "become: yes" on Windows
- { role: Datadog.datadog, become: yes }
vars:
datadog_api_key: "123456"
datadog_agent_major_version: 6
Expand Down Expand Up @@ -321,6 +344,52 @@ Example for sending data to EU site:
datadog_api_key: "123456"
```
### Making the playbook work on Windows
On Windows, the `become: yes` option is not needed (and will make the role fail, as ansible won't be able to use it).

Below are two methods to make the above playbook work with Windows hosts:

### Using the inventory file (recommended)

Set the `ansible_become` option to `no` in the inventory file for each Windows host:

```ini
[servers]
linux1 ansible_host=127.0.0.1
linux2 ansible_host=127.0.0.2
windows1 ansible_host=127.0.0.3 ansible_become=no
windows2 ansible_host=127.0.0.4 ansible_become=no
```

To avoid repeating the same configuration for all Windows hosts, you can also group them and set the variable at the group level:
```ini
[linux]
linux1 ansible_host=127.0.0.1
linux2 ansible_host=127.0.0.2
[windows]
windows1 ansible_host=127.0.0.3
windows2 ansible_host=127.0.0.4
[windows:vars]
ansible_become=no
```

### Using the playbook file

Alternatively, if your playbook **only runs on Windows hosts**, you can do the following in the playbook file:

```yml
- hosts: servers
roles:
- { role: Datadog.datadog }
vars:
...
```

**Warning:** this configuration will fail on Linux hosts (as it's not setting `become: yes` for them). Only use it if the playbook is specific to Windows hosts. Otherwise use the [inventory file method](#using-the-inventory-file-recommended).

## APM

To enable APM with Agent v6 use the following configuration:
Expand Down
4 changes: 4 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
- include_tasks: parse-version.yml
when: datadog_agent_version | length > 0
run_once: true

- include_tasks: pkg-debian.yml
when: ansible_os_family == "Debian"

Expand Down
32 changes: 32 additions & 0 deletions tasks/parse-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- 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>[^-\s]+)?(?:-(?P<release>[0-9]+))?'

- name: Set version vars
set_fact:
datadog_epoch: "{{ agent_version.0 }}"
datadog_major: "{{ agent_version.1 }}"
datadog_minor: "{{ agent_version.2 }}"
datadog_bugfix: "{{ agent_version.3 }}"
datadog_suffix: "{{ agent_version.4 }}"
datadog_release: "{{ agent_version.5 }}"

- name: Fill empty version epoch with default
set_fact:
datadog_epoch: "1"
when: datadog_epoch | length == 0

- name: Fill empty version release with default
set_fact:
datadog_release: "1"
when: datadog_release | length == 0

- name: Set OS-specific versions
set_fact:
datadog_agent_debian_version: "{{ datadog_epoch }}:{{ datadog_major }}.{{ datadog_minor }}.{{ datadog_bugfix }}{{ datadog_suffix }}-{{ datadog_release }}"
datadog_agent_redhat_version: "{{ datadog_major }}.{{ datadog_minor }}.{{ datadog_bugfix }}{{ datadog_suffix }}-{{ datadog_release }}"
datadog_agent_suse_version: "{{ datadog_epoch }}:{{ datadog_major }}.{{ datadog_minor }}.{{ datadog_bugfix }}{{ datadog_suffix }}-{{ datadog_release }}"
datadog_agent_windows_version: "{{ datadog_major }}.{{ datadog_minor }}.{{ datadog_bugfix }}{{ datadog_suffix }}"
6 changes: 3 additions & 3 deletions tasks/pkg-debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@

- name: Ensure pinned version of Datadog agent is installed
apt:
name: "datadog-agent={{ datadog_agent_version }}"
name: "datadog-agent={{ datadog_agent_debian_version }}"
state: present
force: "{{ datadog_agent_allow_downgrade }}"
update_cache: yes
cache_valid_time: "{{ datadog_apt_cache_valid_time }}"
when: (datadog_agent_version | length != 0) and (not ansible_check_mode)
when: (datadog_agent_debian_version is defined) and (not ansible_check_mode)

- name: Ensure Datadog agent is installed
apt:
name: datadog-agent
state: latest # noqa 403
update_cache: yes
cache_valid_time: "{{ datadog_apt_cache_valid_time }}"
when: (datadog_agent_version | length == 0) and (not ansible_check_mode)
when: (datadog_agent_debian_version is not defined) and (not ansible_check_mode)
6 changes: 3 additions & 3 deletions tasks/pkg-redhat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@

- name: Install pinned datadog-agent package
yum:
name: "datadog-agent-{{ datadog_agent_version }}"
name: "datadog-agent-{{ datadog_agent_redhat_version }}"
state: present
allow_downgrade: "{{ datadog_agent_allow_downgrade }}"
when: (datadog_agent_version | length != 0) and (not ansible_check_mode)
when: (datadog_agent_redhat_version is defined) and (not ansible_check_mode)
notify: restart datadog-agent

- name: Install latest datadog-agent package
yum:
name: datadog-agent
update_cache: yes
state: latest # noqa 403
when: (datadog_agent_version | length == 0) and (not ansible_check_mode)
when: (datadog_agent_redhat_version is not defined) and (not ansible_check_mode)
6 changes: 3 additions & 3 deletions tasks/pkg-suse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@

- name: Install pinned datadog-agent package
zypper:
name: "datadog-agent={{ datadog_agent_version }}"
name: "datadog-agent={{ datadog_agent_suse_version }}"
state: present
oldpackage: "{{ datadog_agent_allow_downgrade }}"
when: (datadog_agent_version | length != 0) and (not ansible_check_mode)
when: (datadog_agent_suse_version is defined) and (not ansible_check_mode)
notify: restart datadog-agent

- name: Install latest datadog-agent package
zypper:
name: datadog-agent
state: latest # noqa 403
when: (datadog_agent_version | length == 0) and (not ansible_check_mode)
when: (datadog_agent_suse_version is not defined) and (not ansible_check_mode)
notify: restart datadog-agent
4 changes: 2 additions & 2 deletions tasks/pkg-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
&$env:temp\fix_6_14.ps1
- include_tasks: win_agent_latest.yml
when: datadog_agent_version | length == 0
when: datadog_agent_windows_version is not defined

- include_tasks: win_agent_version.yml
when: not (datadog_agent_version | length == 0)
when: datadog_agent_windows_version is defined

- name: show URL var
debug:
Expand Down
2 changes: 1 addition & 1 deletion tasks/win_agent_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

- name: set agent download filename to a specific version
set_fact:
dd_download_url: "{{ datadog_windows_versioned_url }}-{{ datadog_agent_version }}.msi"
dd_download_url: "{{ datadog_windows_versioned_url }}-{{ datadog_agent_windows_version }}.msi"

0 comments on commit 102d6ba

Please sign in to comment.