Skip to content

Commit b57b69a

Browse files
Added ansible support for windows (#1826)
* Added ansible support for windows * removed conflict * handles the arguements * updated readme * changeLog added * api_url fixed * Fix opamp argument --------- Co-authored-by: Gourav garg <ggarg2906@gmail.com>
1 parent c3e110f commit b57b69a

File tree

3 files changed

+135
-60
lines changed

3 files changed

+135
-60
lines changed

.changelog/1826.changed.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ansible support for windows

examples/ansible/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
# Ansible playbook to install Sumo Logic Distribution for OpenTelemetry Collector
22

3-
This playbook will install Sumo Logic Distro of [OpenTelemetry Collector][otc_link].
3+
This playbook will install Sumo Logic Distro of [OpenTelemetry Collector][otc_link] on both **Linux/Mac** and **Windows** hosts.
4+
5+
## Controller Node (Where You Run Ansible)
6+
7+
- Must be a **Linux/Mac environment**
8+
- On Windows, use **WSL (Windows Subsystem for Linux)** with Ansible installed
9+
10+
## Target Nodes (Where the Collector Will Be Installed)
11+
12+
- **Windows Hosts**:
13+
- PowerShell 5.1 or later
14+
- WinRM enabled and accessible from the controller
15+
- Ansible user must have administrative privileges
416

517
## Running playbook
618

Lines changed: 121 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,127 @@
11
- name: Install and configure Sumo OT distro
22
hosts: sumologic_otel_collector_hosts
3-
become: true
43
gather_facts: true
54
vars_files:
65
- vars/default.yaml
6+
77
tasks:
8-
- name: Download install script
9-
ansible.builtin.get_url:
10-
url: "https://download-otel.sumologic.com/latest/download/install.sh"
11-
dest: /tmp/install.sh
12-
mode: 0755
13-
- name: Create install script argument list
14-
ansible.builtin.set_fact:
15-
install_script_args: ['--download-timeout 300']
16-
- name: Add tags to install script argument list
17-
ansible.builtin.set_fact:
18-
install_script_args: "{{ install_script_args + [ '--tag ' ~ item.key ~ '=' ~ item.value ] }}"
19-
loop: "{{ collector_tags | dict2items }}"
20-
- name: Add version to install script argument list
21-
ansible.builtin.set_fact:
22-
install_script_args: "{{ install_script_args + [ '--version ' ~ version ] }}"
23-
when: version is defined
24-
- name: Add api_url to install script argument list
25-
ansible.builtin.set_fact:
26-
install_script_args: "{{ install_script_args + [ '--api ' ~ api_url ] }}"
27-
when: api_url is defined
28-
- name: Disable systemd via install script argument list
29-
ansible.builtin.set_fact:
30-
install_script_args: "{{ install_script_args + ['--skip-systemd'] }}"
31-
when: not systemd_service
32-
- name: Add remotely managed to install script argument list
33-
ansible.builtin.set_fact:
34-
install_script_args: "{{ install_script_args + ['--remotely-managed'] }}"
35-
when: remotely_managed | default(false)
36-
- name: Add opamp_api_url to install script argument list
37-
ansible.builtin.set_fact:
38-
install_script_args: "{{ install_script_args + [ '--opamp-api ' ~ opamp_api_url ] }}"
39-
when: opamp_api_url is defined
40-
- name: Run install script
41-
environment:
42-
SUMOLOGIC_INSTALLATION_TOKEN: "{{ installation_token | mandatory }}"
43-
ansible.builtin.command: "bash /tmp/install.sh {{ install_script_args | join(' ') }}"
44-
changed_when: true
45-
- name: "Copy configuration files to /etc/otelcol-sumo/conf.d"
46-
ansible.builtin.copy:
47-
src: "{{ src_config_path }}"
48-
dest: /etc/otelcol-sumo/conf.d
49-
owner: otelcol-sumo
50-
group: otelcol-sumo
51-
mode: 0640
52-
when: src_config_path is defined
53-
- name: "Copy environment files to /etc/otelcol-sumo/env"
54-
ansible.builtin.copy:
55-
src: "{{ src_env_path }}"
56-
dest: /etc/otelcol-sumo/env
57-
owner: root
58-
group: root
59-
mode: 0600
60-
when: src_env_path is defined
61-
- name: Restart service
62-
service:
63-
name: otelcol-sumo
64-
state: restarted
65-
when: (src_config_path is defined) or (src_env_path is defined)
8+
- block:
9+
- name: Download install script
10+
ansible.builtin.get_url:
11+
url: "https://github.com/SumoLogic/sumologic-otel-collector-packaging/releases/latest/download/install.sh"
12+
dest: /tmp/install.sh
13+
mode: 0755
14+
- name: Create install script argument list
15+
ansible.builtin.set_fact:
16+
install_script_args: ['--download-timeout 300']
17+
- name: Add tags to install script argument list
18+
ansible.builtin.set_fact:
19+
install_script_args: "{{ install_script_args + [ '--tag ' ~ item.key ~ '=' ~ item.value ] }}"
20+
loop: "{{ collector_tags | dict2items }}"
21+
- name: Add version to install script argument list
22+
ansible.builtin.set_fact:
23+
install_script_args: "{{ install_script_args + [ '--version ' ~ version ] }}"
24+
when: version is defined
25+
- name: Add api_url to install script argument list
26+
ansible.builtin.set_fact:
27+
install_script_args: "{{ install_script_args + [ '--api ' ~ api_url ] }}"
28+
when: api_url is defined
29+
- name: Disable systemd via install script argument list
30+
ansible.builtin.set_fact:
31+
install_script_args: "{{ install_script_args + ['--skip-systemd'] }}"
32+
when: not systemd_service
33+
- name: Add remotely managed to install script argument list
34+
ansible.builtin.set_fact:
35+
install_script_args: "{{ install_script_args + ['--remotely-managed'] }}"
36+
when: remotely_managed | default(false)
37+
- name: Add opamp_api_url to install script argument list
38+
ansible.builtin.set_fact:
39+
install_script_args: "{{ install_script_args + [ '--opamp-api ' ~ opamp_api_url ] }}"
40+
when: opamp_api_url is defined
41+
- name: Run install script
42+
environment:
43+
SUMOLOGIC_INSTALLATION_TOKEN: "{{ installation_token | mandatory }}"
44+
ansible.builtin.command: "bash /tmp/install.sh {{ install_script_args | join(' ') }}"
45+
changed_when: true
46+
- name: Copy configuration files
47+
ansible.builtin.copy:
48+
src: "{{ src_config_path }}"
49+
dest: /etc/otelcol-sumo/conf.d
50+
owner: otelcol-sumo
51+
group: otelcol-sumo
52+
mode: 0640
53+
when: src_config_path is defined
54+
- name: Copy environment files
55+
ansible.builtin.copy:
56+
src: "{{ src_env_path }}"
57+
dest: /etc/otelcol-sumo/env
58+
owner: root
59+
group: root
60+
mode: 0600
61+
when: src_env_path is defined
62+
- name: Restart otelcol-sumo service
63+
ansible.builtin.service:
64+
name: otelcol-sumo
65+
state: restarted
66+
when: (src_config_path is defined) or (src_env_path is defined)
67+
become: true
68+
when: ansible_os_family != 'Windows'
69+
- block:
70+
- name: Download install script
71+
win_get_url:
72+
url: "https://download-otel.sumologic.com/latest/download/install.ps1"
73+
dest: "C:\\Windows\\Temp\\install.ps1"
74+
- name: Build tag arguments
75+
set_fact:
76+
ps_tags: >-
77+
@{
78+
{% for item in collector_tags | dict2items %}
79+
'{{ item.key }}' = '{{ item.value }}'{% if not loop.last %}; {% endif %}
80+
{% endfor %}
81+
}
82+
- name: Initialize install script argument list
83+
set_fact:
84+
win_install_args: []
85+
- name: Add version to install script argument list
86+
set_fact:
87+
win_install_args: "{{ win_install_args + [ '-Version ' ~ version ] }}"
88+
when: version is defined
89+
- name: Add api_url to install script argument list
90+
set_fact:
91+
win_install_args: "{{ win_install_args + [ '-Api ' ~ api_url ] }}"
92+
when: api_url is defined
93+
- name: Add remotely managed to install script argument list
94+
set_fact:
95+
win_install_args: "{{ win_install_args + ['-RemotelyManaged ' ~ remotely_managed] }}"
96+
when: remotely_managed | default(false)
97+
- name: Add opamp_api to install script argument list
98+
set_fact:
99+
win_install_args: "{{ win_install_args + [ '-OpAmpApi ' ~ opamp_api ] }}"
100+
when: opamp_api is defined
101+
- name: Run install script
102+
win_shell: |
103+
Set-ExecutionPolicy RemoteSigned -Scope Process -Force
104+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
105+
$tags = {{ ps_tags }}
106+
& 'C:\Windows\Temp\install.ps1' -InstallationToken "{{ installation_token }}" -Tags $tags {{ win_install_args | join(" ") }}
107+
args:
108+
executable: powershell.exe
109+
environment:
110+
SUMOLOGIC_INSTALLATION_TOKEN: "{{ installation_token }}"
111+
- name: Copy configuration files
112+
win_copy:
113+
src: "{{ src_config_path }}"
114+
dest: "C:\\ProgramData\\SumoLogic\\otelcol-sumo\\conf.d"
115+
when: src_config_path is defined
116+
- name: Copy environment files
117+
win_copy:
118+
src: "{{ src_env_path }}"
119+
dest: "C:\\ProgramData\\SumoLogic\\otelcol-sumo\\env"
120+
when: src_env_path is defined
121+
- name: Restart otelcol-sumo service
122+
win_service:
123+
name: otelcol-sumo
124+
state: restarted
125+
when: src_config_path is defined or src_env_path is defined
126+
become: false
127+
when: ansible_os_family == 'Windows'

0 commit comments

Comments
 (0)