Skip to content

Commit 2587a98

Browse files
test
1 parent c00277e commit 2587a98

File tree

13 files changed

+246
-0
lines changed

13 files changed

+246
-0
lines changed

.github/workflows/ansible.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- 'deployments/ansible/galaxy.yml'
1313
branches:
1414
- main
15+
- ansible-discovery-mode
1516
pull_request:
1617
paths:
1718
- '.github/workflows/ansible.yml'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{% if item.image not in ["opensuse12", "opensuse15", "centos9"] %}
2+
FROM geerlingguy/docker-{{ item.image }}-ansible:latest
3+
{% if item.image == "centos8" %}
4+
RUN sed -i 's|#mirrorlist|mirrorlist|g' /etc/yum.repos.d/CentOS*.repo
5+
RUN sed -i 's|^baseurl|#baseurl|' /etc/yum.repos.d/CentOS*.repo
6+
RUN sed -i 's|\$releasever|8-stream|g' /etc/yum.repos.d/CentOS*.repo
7+
{% elif item.image == "debian9" %}
8+
RUN sed -i 's|http://.*.debian.org|http://archive.debian.org|' /etc/apt/sources.list
9+
RUN sed -i '/stretch-updates/d' /etc/apt/sources.list
10+
{% endif %}
11+
{% elif item.image == "centos9" %}
12+
FROM quay.io/centos/centos:stream9
13+
ENV container docker
14+
RUN rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
15+
RUN dnf install -y initscripts sudo systemd
16+
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i = \
17+
"systemd-tmpfiles-setup.service" ] || rm -f $i; done); \
18+
rm -f /lib/systemd/system/multi-user.target.wants/*;\
19+
rm -f /lib/systemd/system/local-fs.target.wants/*; \
20+
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
21+
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
22+
rm -f /lib/systemd/system/basic.target.wants/*;\
23+
rm -f /lib/systemd/system/anaconda.target.wants/*;
24+
# Disable requiretty.
25+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
26+
CMD ["/usr/sbin/init"]
27+
{% else %}
28+
{% if item.image == "opensuse12" %}
29+
FROM opensuse/leap:42
30+
RUN sed -i 's|download.opensuse.org|ftp5.gwdg.de/pub/opensuse/discontinued|' /etc/zypp/repos.d/*.repo
31+
RUN zypper -n clean && zypper -n refresh
32+
RUN zypper -n install -l ansible dbus-1 rpm-python sudo systemd-sysvinit
33+
{% else %}
34+
FROM opensuse/leap:15
35+
RUN sed -i 's|download.opensuse.org|provo-mirror.opensuse.org|' /etc/zypp/repos.d/*.repo
36+
RUN zypper -n install -l ansible dbus-1 python3-rpm sudo systemd-sysvinit
37+
{% endif %}
38+
39+
ENV container docker
40+
41+
RUN (cd /usr/lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i = \
42+
"systemd-tmpfiles-setup.service" ] || rm -f $i; done); \
43+
rm -f /usr/lib/systemd/system/multi-user.target.wants/*;\
44+
rm -f /usr/lib/systemd/system/local-fs.target.wants/*; \
45+
rm -f /usr/lib/systemd/system/sockets.target.wants/*udev*; \
46+
rm -f /usr/lib/systemd/system/sockets.target.wants/*initctl*; \
47+
rm -f /usr/lib/systemd/system/basic.target.wants/*;
48+
49+
# Disable requiretty.
50+
RUN sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers
51+
52+
# Install Ansible inventory file.
53+
RUN mkdir -p /etc/ansible
54+
RUN echo -e '[local]\nlocalhost ansible_connection=local' > /etc/ansible/hosts
55+
56+
VOLUME [ "/sys/fs/cgroup" ]
57+
CMD ["/sbin/init"]
58+
{% endif %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: Converge scenario with custom variables
3+
hosts: all
4+
become: yes
5+
vars:
6+
splunk_access_token: fake-token
7+
splunk_realm: fake-realm
8+
splunk_discovery_mode: yes
9+
splunk_discovery_properties_yaml: |
10+
---
11+
splunk:
12+
discovery:
13+
extensions:
14+
k8s_observer:
15+
enabled: false
16+
docker_observer
17+
enabled: false
18+
splunk_discovery_properties_dest: /tmp/test.discovery.yaml
19+
tasks:
20+
- name: "Include signalfx.splunk_otel_collector.collector role"
21+
include_role:
22+
name: "signalfx.splunk_otel_collector.collector"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# no default config provided, make sure to set --base-config molecule argument instead
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
- name: Verify scenario with custom variables
3+
hosts: all
4+
gather_facts: true
5+
become: yes
6+
tasks:
7+
- name: Import shared verification tasks
8+
ansible.builtin.import_tasks: ../shared/verify_tasks.yml
9+
10+
- name: Assert td-agent service is not installed
11+
assert:
12+
that: "'td-agent.service' not in ansible_facts.services"
13+
14+
- name: Assert SPLUNK_ACCESS_TOKEN env var is set
15+
ansible.builtin.lineinfile:
16+
line: SPLUNK_ACCESS_TOKEN=fake-token
17+
dest: /etc/otel/collector/splunk-otel-collector.conf
18+
state: present
19+
check_mode: yes
20+
21+
- name: Assert SPLUNK_REALM env var is set
22+
ansible.builtin.lineinfile:
23+
line: SPLUNK_REALM=fake-realm
24+
dest: /etc/otel/collector/splunk-otel-collector.conf
25+
state: present
26+
check_mode: yes
27+
28+
- name: Assert SPLUNK_INGEST_URL env var is set
29+
ansible.builtin.lineinfile:
30+
line: SPLUNK_INGEST_URL=https://ingest.fake-realm.signalfx.com
31+
dest: /etc/otel/collector/splunk-otel-collector.conf
32+
state: present
33+
check_mode: yes
34+
35+
- name: Assert SPLUNK_API_URL env var is set
36+
ansible.builtin.lineinfile:
37+
line: SPLUNK_INGEST_URL=https://api.fake-realm.signalfx.com
38+
dest: /etc/otel/collector/splunk-otel-collector.conf
39+
state: present
40+
check_mode: yes
41+
42+
- name: Assert SPLUNK_TRACE_URL env var is set
43+
ansible.builtin.lineinfile:
44+
line: SPLUNK_TRACE_URL=https://ingest.fake-realm.signalfx.com/v2/trace
45+
dest: /etc/otel/collector/splunk-otel-collector.conf
46+
state: present
47+
check_mode: yes
48+
49+
- name: Assert SPLUNK_HEC_URL env var is set
50+
ansible.builtin.lineinfile:
51+
line: SPLUNK_HEC_URL=https://ingest.fake-realm.signalfx.com/v1/log
52+
dest: /etc/otel/collector/splunk-otel-collector.conf
53+
state: present
54+
check_mode: yes
55+
56+
- name: Assert discovery mode is enabled
57+
ansible.builtin.template:
58+
line: OTELCOL_OPTIONS=--discovery --discovery-properties=/tmp/test.discovery.yaml
59+
dest: /etc/otel/collector/splunk-otel-collector.conf
60+
state: present
61+
check_mode: yes

deployments/ansible/molecule/default/verify.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@
5656
dest: /etc/otel/collector/splunk-otel-collector.conf
5757
state: present
5858
check_mode: yes
59+
60+
- name: Assert discovery mode is not enabled
61+
ansible.builtin.lineinfile:
62+
regexp: .*OTELCOL_OPTIONS=.*--discovery.*
63+
dest: /etc/otel/collector/splunk-otel-collector.conf
64+
state: absent
65+
check_mode: yes
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../default/Dockerfile.j2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Converge scenario with custom variables
3+
hosts: all
4+
become: yes
5+
vars:
6+
splunk_access_token: fake-token
7+
splunk_realm: fake-realm
8+
splunk_discovery_mode: yes
9+
tasks:
10+
- name: "Include signalfx.splunk_otel_collector.collector role"
11+
include_role:
12+
name: "signalfx.splunk_otel_collector.collector"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# no default config provided, make sure to set --base-config molecule argument instead
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
- name: Verify scenario with custom variables
3+
hosts: all
4+
gather_facts: true
5+
become: yes
6+
tasks:
7+
- name: Import shared verification tasks
8+
ansible.builtin.import_tasks: ../shared/verify_tasks.yml
9+
10+
- name: Assert td-agent service is not installed
11+
assert:
12+
that: "'td-agent.service' not in ansible_facts.services"
13+
14+
- name: Assert SPLUNK_ACCESS_TOKEN env var is set
15+
ansible.builtin.lineinfile:
16+
line: SPLUNK_ACCESS_TOKEN=fake-token
17+
dest: /etc/otel/collector/splunk-otel-collector.conf
18+
state: present
19+
check_mode: yes
20+
21+
- name: Assert SPLUNK_REALM env var is set
22+
ansible.builtin.lineinfile:
23+
line: SPLUNK_REALM=fake-realm
24+
dest: /etc/otel/collector/splunk-otel-collector.conf
25+
state: present
26+
check_mode: yes
27+
28+
- name: Assert SPLUNK_INGEST_URL env var is set
29+
ansible.builtin.lineinfile:
30+
line: SPLUNK_INGEST_URL=https://ingest.fake-realm.signalfx.com
31+
dest: /etc/otel/collector/splunk-otel-collector.conf
32+
state: present
33+
check_mode: yes
34+
35+
- name: Assert SPLUNK_API_URL env var is set
36+
ansible.builtin.lineinfile:
37+
line: SPLUNK_INGEST_URL=https://api.fake-realm.signalfx.com
38+
dest: /etc/otel/collector/splunk-otel-collector.conf
39+
state: present
40+
check_mode: yes
41+
42+
- name: Assert SPLUNK_TRACE_URL env var is set
43+
ansible.builtin.lineinfile:
44+
line: SPLUNK_TRACE_URL=https://ingest.fake-realm.signalfx.com/v2/trace
45+
dest: /etc/otel/collector/splunk-otel-collector.conf
46+
state: present
47+
check_mode: yes
48+
49+
- name: Assert SPLUNK_HEC_URL env var is set
50+
ansible.builtin.lineinfile:
51+
line: SPLUNK_HEC_URL=https://ingest.fake-realm.signalfx.com/v1/log
52+
dest: /etc/otel/collector/splunk-otel-collector.conf
53+
state: present
54+
check_mode: yes
55+
56+
- name: Assert discovery mode is enabled
57+
ansible.builtin.lineinfile:
58+
line: OTELCOL_OPTIONS=--discovery
59+
dest: /etc/otel/collector/splunk-otel-collector.conf
60+
state: present
61+
check_mode: yes

deployments/ansible/roles/collector/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ signalfx_dotnet_auto_instrumentation_enable_profiler_memory: false
9696
signalfx_dotnet_auto_instrumentation_global_tags: ""
9797
signalfx_dotnet_auto_instrumentation_iisreset: true
9898
signalfx_dotnet_auto_instrumentation_additional_options: {}
99+
100+
splunk_discovery_mode: false
101+
splunk_discovery_properties_yaml: ""
102+
splunk_discovery_properties_dest: /etc/otel/collector/config.d/properties.discovery.yaml

deployments/ansible/roles/collector/tasks/linux_install.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@
6363
when: splunk_otel_collector_config_source != ''
6464
notify: "restart splunk-otel-collector"
6565

66+
- name: Create the discovery properties file
67+
ansible.builtin.copy:
68+
content: "{{ splunk_discovery_properties_yaml }}"
69+
dest: "{{ splunk_discovery_properties_dest }}"
70+
owner: "{{ splunk_service_user }}"
71+
group: "{{ splunk_service_group }}"
72+
mode: 0644
73+
when: splunk_discovery_properties_yaml != ''
74+
notify: "restart splunk-otel-collector"
75+
6676
- name: Install FluentD
6777
ansible.builtin.import_tasks: linux_install_fluentd.yml
6878
when: install_fluentd and fluentd_supported

deployments/ansible/roles/collector/templates/splunk-otel-collector.conf.j2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ SPLUNK_COLLECTD_DIR={{ splunk_collectd_dir }}
3232
{{ key }}={{ value }}
3333
{% endfor %}
3434
{% endif %}
35+
{% if splunk_discovery_mode is defined and splunk_discovery_mode %}
36+
{% if splunk_discovery_properties_yaml is defined and splunk_discovery_properties_yaml %}
37+
OTELCOL_OPTIONS=--discovery --discovery-properties={{ splunk_discovery_properties_dest }}
38+
{% else %}
39+
OTELCOL_OPTIONS=--discovery
40+
{% endif %}
41+
{% endif %}

0 commit comments

Comments
 (0)