Skip to content

Commit

Permalink
Ansible role for Linux deployment
Browse files Browse the repository at this point in the history
Initial version of the Ansible role for Linux deployment with tests
  • Loading branch information
dmitryax committed May 13, 2021
1 parent 35a52ea commit ad90477
Show file tree
Hide file tree
Showing 32 changed files with 959 additions and 0 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ansible-role-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
on:
pull_request:
paths:
- 'deployments/ansible/roles/splunk-otel-collector/**'

defaults:
run:
working-directory: 'deployments/ansible/roles/splunk-otel-collector'

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint

- name: Lint code.
run: yamllint .

molecule-test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
distro:
- amazonlinux2
- centos7
- centos8
- debian9
- debian10
- ubuntu2004

steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install ansible molecule[docker] docker

- name: Run Molecule tests.
run: molecule --base-config ./molecule/config/docker.yml test --all
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ venv/
__pycache__
*.pyc
.pytest_cache

# Ansible Molecule
.cache
12 changes: 12 additions & 0 deletions deployments/ansible/roles/splunk-otel-collector/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# Based on ansible-lint config
extends: default

rules:
line-length:
max: 120
level: error
key-duplicates: enable
new-lines:
type: unix
truthy: disable
75 changes: 75 additions & 0 deletions deployments/ansible/roles/splunk-otel-collector/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Contributing Guidelines

If you found a bug in the Ansible role, don't hesitate to submit an issue or a
pull request.

## Local development

Testing and validation of this Ansible role is based on
[Ansible Molecule](https://molecule.readthedocs.io/en/latest/).

### MacOS or Windows setup

Development of the role can be done on MacOS or Windows machines. Make sure the
following software is installed:

- [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
- [Vagrant](https://www.vagrantup.com/downloads)
- [Python3](https://www.python.org/downloads)
- Python packages:
- ansible
- molecule
- molecule-vagrant

MacOS installation steps:

```sh
brew tap hashicorp/tap
brew install virtualbox vagrant python3
pip3 install ansible molecule molecule-vagrant
```

Use the following arguments with every molecule command
`--base-config ./molecule/config/vagrant.yml`.

To setup test VMs:
```sh
molecule --base-config ./molecule/config/vagrant.yml create
```

To apply Molecule test playbooks:
```sh
molecule --base-config ./molecule/config/vagrant.yml converge
```

To run the full test suite:
```sh
molecule --base-config ./molecule/config/vagrant.yml test --all
```

### Linux setup

Development on a Linux machine is simpler, all you need is docker.

Linux installation steps:

- Make sure [Python3](https://www.python.org/downloads) is installed
- `pip3 install ansible molecule[docker] docker`

Use the following arguments with every molecule command
`--base-config ./molecule/config/docker.yml`.

To setup test docker containers:
```sh
molecule --base-config ./molecule/config/docker.yml create
```

To apply Molecule playbooks:
```sh
molecule --base-config ./molecule/config/docker.yml converge
```

To run the full test suite:
```sh
molecule --base-config ./molecule/config/docker.yml test --all
```
119 changes: 119 additions & 0 deletions deployments/ansible/roles/splunk-otel-collector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Role Name

Ansible role that installs Splunk OpenTelemetry Connector configured to
collect metrics, traces and logs from Linux machines and send data to [Splunk
Observability Cloud](https://www.splunk.com/en_us/observability.html).

## Prerequisites

- [Splunk Access Token](https://docs.splunk.com/Observability/admin/authentication-tokens/org-tokens.html#admin-org-tokens)
- [Splunk Realm](https://dev.splunk.com/observability/docs/realms_in_endpoints/)
- [Double-check exposed ports](https://github.com/signalfx/splunk-otel-collector/blob/main/docs/security.md#exposed-endpoints)
to make sure your environment doesn't have conflicts. Ports can be changed in the collector's configuration.

## Usage

To install the role, clone the agent repo to your control host and add the
`splunk-otel-collector` role directory to its `roles_path` in `ansible.cfg`,
or use this document's directory as your working directory.

To use this role, simply include the `splunk-otel-collector` role invocation
in your playbook. The following example shows how to use the role in a
playbook with minimal required configuration:

```yaml
- name: Install Splunk OpenTelemetry Connector
hosts: all
become: yes
vars:
splunk_access_token: YOUR_ACCESS_TOKEN
splunk_realm: SPLUNK_REALM
tasks:
- name: "Include splunk-otel-collector"
include_role:
name: "splunk-otel-collector"
```
## Role Variables
- `splunk_access_token` (**Required**): The Splunk access token to
authenticate requests.

- `splunk_realm`: Which realm to send the data to. The `SPLUNK_REALM`
environment variable will be set with this value for the Splunk OTel
Collector service. (**default:** `us0`)

- `splunk_ingest_url`: The Splunk ingest URL, e.g.
`https://ingest.us0.signalfx.com`. The `SPLUNK_INGEST_URL` environment
variable will be set with this value for the collector service. (**default:**
`https://ingest.{{ splunk_realm }}.signalfx.com`)

- `splunk_api_url`: The Splunk API URL, e.g. `https://api.us0.signalfx.com`.
The `SPLUNK_API_URL` environment variable will be set with this value for the
collector service. (**default:** `https://api.{{ splunk_realm }}.signalfx.com`)

- `collector_version`: Version of the collector package to install, e.g.
`0.26.0`. (**default:** `latest`)

- `collector_config`: Splunk OTel Collector config YAML file. Can be set to
/etc/otel/collector/gateway_config.yaml to install the collector in gateway
mode. (**default:** `/etc/otel/collector/agent_config.yaml`)

- `collector_config_source`: Source path to a Splunk OTel Collector config YAML
file on a control node that will be uploaded and set in place of
`collector_config` in remote nodes. Can be used to submit a custom collector
config, e.g. `./custom_collector_config.yaml`. (**default:** `""` meaning
that nothing will be copied and existing `collector_config` will be used)

- `splunk_bundle_dir`: The path to the [Smart Agent bundle directory](
https://github.com/signalfx/splunk-otel-collector/blob/main/internal/extension/smartagentextension/README.md).
The default path is provided by the collector package. If the specified path
is changed from the default value, the path should be an existing directory
on the node. The `SPLUNK_BUNDLE_DIR` environment variable will be set to
this value for the collector service. (**default:**
`/usr/lib/splunk-otel-collector/agent-bundle`)

- `splunk_collectd_dir`: The path to the collectd config directory for the
Smart Agent bundle. The default path is provided by the collector package.
If the specified path is changed from the default value, the path should be
an existing directory on the node. The `SPLUNK_COLLECTD_DIR` environment
variable will be set to this value for the collector service. (**default:**
`/usr/lib/splunk-otel-collector/agent-bundle`)

- `service_user` and `service_group` (Linux only): Set the user/group
ownership for the collector service. The user/group will be created if they
do not exist. (**default:** `splunk-otel-collector`)

- `memory_total_mib`: Amount of memory in MiB allocated to the Splunk OTel
Collector. (**default:** `512`)

- `ballast_size_mib`: Memory ballast size in MiB that will be set to the Splunk
OTel Collector. (**default:** 1/3 of `memory_total_mib`)

- `install_fluentd`: Whether to install/manage fluentd and dependencies for log
collection. The dependencies include [capng_c](
https://github.com/fluent-plugins-nursery/capng_c) for enabling
[Linux capabilities](
https://docs.fluentd.org/deployment/linux-capability),
[fluent-plugin-systemd](
https://github.com/fluent-plugin-systemd/fluent-plugin-systemd) for systemd
journal log collection, and the required libraries/development tools.
(**default:** `true`)

- `td_agent_version`: Version of td-agent (fluentd package) that will be
installed (**default:** `3.3.0` for Debian jessie, `3.7.1` for Debian
stretch, and `4.1.1` for other distros`)

- `fluentd_config`: Path to the fluentd config file on the remote host.
(**default:** `/etc/otel/collector/fluentd/fluent.conf`)

- `fluentd_config_source`: Source path to a fluentd config file on a
control node that will be uploaded and set in place of `fluentd_config` on
remote nodes. Can be used to submit a custom fluentd config,
e.g. `./custom_fluentd_config.conf`. (**default:** `""` meaning
that nothing will be copied and existing `fluentd_config` will be used)

## Contributing

Check [Contributing guidelines](./CONTRIBUTING.md) if you see something that
needs to be improved in this Ansible role.
35 changes: 35 additions & 0 deletions deployments/ansible/roles/splunk-otel-collector/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
# defaults file for splunk-otel-collector role vars

# splunk_access_token is REQUIRED variable
splunk_access_token: ""

splunk_realm: us0

collector_version: latest

# Set this variable to /etc/otel/collector/gateway_config.yaml in order to
# deploy splunk-otel-collector in gateway mode
collector_config: /etc/otel/collector/agent_config.yaml
# Set collector_config_source to copy a custom config from a local path
collector_config_source: ""

service_user: splunk-otel-collector
service_group: splunk-otel-collector

memory_total_mib: 512
# 1/3 of memory_mib by default
ballast_size_mib: ""

install_fluentd: true

# Explicitly set version of td-agent,
# By default: 3.3.0 for Debian jessie, 3.7.1 for Debian stretch,
# and 4.1.1 for other distros.
td_agent_version: ""

fluentd_config: /etc/otel/collector/fluentd/fluent.conf
fluentd_config_source: ""

agent_bundle_dir: /usr/lib/splunk-otel-collector/agent-bundle
splunk_collectd_dir: /usr/lib/splunk-otel-collector/agent-bundle/run/collectd
22 changes: 22 additions & 0 deletions deployments/ansible/roles/splunk-otel-collector/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
# handlers file for splunk-otel-collector

- name: Reload systemd daemon
ansible.builtin.systemd:
daemon_reload: yes
listen:
- reload otel-collector
- reload td-agent

- name: Restart td-agent
ansible.builtin.service:
name: td-agent
state: restarted
when: install_fluentd
listen: "reload td-agent"

- name: Restart Splunk OpenTelemetry Collector
ansible.builtin.service:
name: splunk-otel-collector
state: restarted
listen: "reload otel-collector"
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# molecule config based on docker for CI usage on a Linux system only

driver:
name: docker
platforms:
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos8}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# molecule config based on vagrant and virtualbox for local usage on any OS

driver:
name: vagrant
provider:
name: virtualbox
platforms:
- name: focal64
box: ubuntu/focal64
- name: centos8
box: centos/8
- name: buster64
box: debian/buster64
- name: amazonlinux
box: bento/amazonlinux-2
provisioner:
name: ansible
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
- name: Converge scenario with custom variables
hosts: all
become: yes
vars:
splunk_access_token: fake-token
collector_version: 0.24.3
collector_config: /etc/otel/collector/custom_config.yml
collector_config_source: ./custom_collector_config.yml
service_user: custom-user
service_group: custom-group
memory_total_mib: 256
ballast_size_mib: 100
fluentd_config: /etc/otel/collector/fluentd/custom_fluentd.conf
fluentd_config_source: ./custom_fluentd_config.conf
tasks:
- name: "Include splunk-otel-collector"
include_role:
name: "splunk-otel-collector"
Loading

0 comments on commit ad90477

Please sign in to comment.