Skip to content

Commit

Permalink
Fix errors coming from linters (#61)
Browse files Browse the repository at this point in the history
* Fix ansible-lint errors

* Fix galaxy.yaml

* Fix pep8 issues

* Fix pylint issues

* Fix shellcheck issues

* Remove venv from collection build

* Update README.md and galaxy.yml files

* Fix ansible-lint errors

* Test suppressing linter errors

* Revert "Test suppressing linter errors"

This reverts commit 65e4039.

* Add ansible-lint test

* Refactor oneagent installer to pass ctl args safely

* Reformat files

* Configure pre-commit hooks

* fixup! Reformat files

* fixup! Refactor oneagent installer to pass ctl args safely

* add pylint settings to pyproject file

* touch up shell scripts

---------

Co-authored-by: wojciech.stechura <wojciech.stechura@dynatrace.com>
Co-authored-by: Jakub Rak <jakub.rak@dynatrace.com>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent 2effbf1 commit eb04a21
Show file tree
Hide file tree
Showing 42 changed files with 603 additions and 377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: run-sanity-tests
description: "Runs sanity tests"
name: run-sanity-and-linter-tests
description: "Runs sanity and linter tests"

runs:
using: composite
Expand All @@ -25,3 +25,7 @@ runs:
- name: "Run sanity test"
shell: bash
run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-test sanity && popd

- name: "Run linter test"
shell: bash
run: pushd ~/.ansible/collections/ansible_collections/dynatrace/oneagent && ansible-lint && popd
2 changes: 1 addition & 1 deletion .github/actions/setup-build-environment/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ runs:
python-version: '3.10'
- name: "Install dependencies"
shell: bash
run: pip install ansible
run: pip install ansible ansible-lint
2 changes: 1 addition & 1 deletion .github/actions/upload-collection/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ runs:
with:
name: dynatrace-oneagent-${{ github.sha }}
retention-days: 7
path: dynatrace-oneagent*
path: dynatrace-oneagent*
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: Build the collection
uses: ./.github/actions/build-collection
- name: Run sanity tests
uses: ./.github/actions/run-sanity-tests
uses: ./.github/actions/run-sanity-and-linter-tests
- name: Run component tests
uses: ./.github/actions/run-component-tests
4 changes: 2 additions & 2 deletions .github/workflows/build-test-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ name: "Build, test and publish"
on:
push:
tags:
- "v*.*.*"
- "v*.*.*"

jobs:
build-test-and-publish:
Expand All @@ -34,7 +34,7 @@ jobs:
- name: Build the collection
uses: ./.github/actions/build-collection
- name: Run sanity tests
uses: ./.github/actions/run-sanity-tests
uses: ./.github/actions/run-sanity-and-linter-tests
- name: Run component tests
uses: ./.github/actions/run-component-tests
- name: Publish to Ansible Galaxy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-test-and-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
name: "Build, test and upload"
on:
push:
branches: [ "master" ]
branches: ["master"]
workflow_dispatch:

jobs:
Expand All @@ -30,7 +30,7 @@ jobs:
- name: Build the collection
uses: ./.github/actions/build-collection
- name: Run sanity tests
uses: ./.github/actions/run-sanity-tests
uses: ./.github/actions/run-sanity-and-linter-tests
- name: Run component tests
uses: ./.github/actions/run-component-tests
- name: Upload the collection
Expand Down
41 changes: 39 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
---
repos:
- repo: https://github.com/ansible/ansible-lint
rev: v24.2.2
rev: v24.12.2
hooks:
- id: ansible-lint
pass_filenames: false
args: ['--exclude', 'roles/oneagent/examples', 'tests/component/resources/ansible/oneagent.yml']

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black

- repo: local
hooks:
- id: shfmt
name: shfmt
additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt@v3.8.0]
entry: shfmt
language: golang
exclude: roles/oneagent/tests/resources/installers/Dynatrace-OneAgent-Linux.sh
args:
- "-s"
- "-w"
types: [shell]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: "v0.10.0.1"
hooks:
- id: shellcheck
exclude: gradlew
args:
- "--external-sources"

- repo: https://github.com/adrienverge/yamllint
rev: "v1.35.0"
hooks:
- id: yamllint
files: \.(yaml|yml)
6 changes: 6 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
rules:
document-start:
ignore: |
/.github
line-length: disable
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ All notable changes to this project will be documented in this file.
- Removed `oneagent_remove_signature` parameter.
- Added ability to configure installation using `oneagentctl`.
- Removed the need to provide the required parameters in case of uninstallation.
- Added node restart option.
- Added node restart option.

## [0.3.0] - 2021-02-12

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ configuration of OneAgent and ensures the OneAgent service remains in a running

## Requirements

* Ansible >= 2.15.0
* pywinrm >= 0.4.3 (Windows only)
- Ansible >= 2.15.0
- pywinrm >= 0.4.3 (Windows only)

## Installation

Expand Down Expand Up @@ -44,15 +44,16 @@ broken in the latest version (please report an issue in this repository). Use th
ansible-galaxy collection install dynatrace.oneagent:==1.0.0
```

See [using Ansible collections](https://docs.ansible.com/ansible/devel/user_guide/collections_using.html) for more
details.
See [using Ansible collections](https://docs.ansible.com/ansible/devel/user_guide/collections_using.html) for more details.

## Use Cases

See [OneAgent role README](roles/oneagent/README.md) for more details.

## Testing

The collection was tested against Ansible sanity tests and component tests. The latter runs regular deployment with
the installer and checks veriety of installation scenarios.
See [OneAgent role tests README](roles/oneagent/tests/README.md) for more details.

## Support
Expand Down
15 changes: 10 additions & 5 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@ readme: README.md
authors:
- Dynatrace LLC
description: Module to install and configure Dynatrace OneAgent deployment
license:
- MIT
license_file: LICENSE
tags:
- dynatrace
- oneagent
- monitoring
- agent
- deployment
- monitoring
- infrastructure
- linux
- windows
repository: https://github.com/Dynatrace/Dynatrace-OneAgent-Ansible
documentation: https://docs.dynatrace.com/docs/setup-and-configuration/dynatrace-oneagent/deployment-orchestration/ansible
build_ignore:
- roles/oneagent/tests
- roles/oneagent/examples
- .github
- .pre-commit-config.yaml
- .gitignore
- venv
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.pylint.BASIC]
max-line-length = 120

[tool.pylint.'MESSAGES CONTROL']
disable = '''
missing-docstring,
'''

[tool.black]
line-length = 120
60 changes: 29 additions & 31 deletions roles/oneagent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

## Requirements

* OneAgent version 1.199+.
* Script access to the OneAgent installer file. You can either:
* configure the script to download the installer directly from your Dynatrace environment,
* download it yourself and upload it to the primary node.
- OneAgent version 1.199+.
- Script access to the OneAgent installer file. You can either:
- configure the script to download the installer directly from your Dynatrace environment,
- download it yourself and upload it to the primary node.

### Direct download from your environment

The script utilizes [Deployment API] to download a platform-specific installer to the target machine.
You will need to supply the role with information required to authenticate the API call in your environment:

* The environment URL:
* **SaaS**: `https://{your-environment-id}.live.dynatrace.com`
* **Managed**: `https://{your-domain}/e/{your-environment-id}`
* The [PaaS token] of your environment
- The environment URL:
- **SaaS**: `https://{your-environment-id}.live.dynatrace.com`
- **Managed**: `https://{your-domain}/e/{your-environment-id}`
- The [PaaS token] of your environment

### Local installer

Expand All @@ -27,45 +27,43 @@ If you don't specify the installer, the script attempts to use the direct downlo

The role is capable of configuring existing installation by utilizing `oneagentctl`.
There are 2 ways of applying configuration:

- In case the Agent in the same or lower version is installed on specified host already, the script
uses provided installation parameters and runs `oneagentctl` with them, skipping installation procedure.
- In case no `environment_url`, `paas_token` and `local_installer` parameters are provided,
the script runs `oneagentctl` with provided parameters directly.
uses provided installation parameters and runs `oneagentctl` with them, skipping installation procedure.
- In case no `environment_url`, `paas_token` and `local_installer` parameters are provided,
the script runs `oneagentctl` with provided parameters directly.

For full list of suitable parameters, see [OneAgent configuration via command-line interface].

## Variables

The following variables are available in `defaults/main/` and can be overridden:

| Name | Default | Description
|-|-|-
| `oneagent_environment_url` | `-` | The URL of the target Dynatrace environment (see [Direct download from your environment](#direct-download-from-your-environment)).
| `oneagent_paas_token` | `-` | The [PaaS Token] retrieved from the "Deploy Dynatrace" installer page.
| `oneagent_local_installer` | `-` | The Path to OneAgent installer stored on the main node.
| `oneagent_installer_arch` | `-` | Specifies the OneAgent installer architecture.
| `oneagent_version` | `latest` | The required version of the OneAgent in the `1.199.247.20200714-111723` format. See [Deployment API - GET available versions of OneAgent] for more details.
| `oneagent_download_dir` | Linux: `$TEMP` or `/tmp`</br>Windows: `%TEMP%` or `C:\Windows\Temp` | Installer download directory. For Linux and AIX, the directory must not contain spaces. Will be created if it does not exist.
| `oneagent_install_args` | `-` Dynatrace OneAgent installation parameters defined as a list of items.
| `oneagent_platform_install_args` | `-` | Additional list of platform-specific installation parameters, appended to `oneagent_install_args' when run on a respective platform.
| `oneagent_preserve_installer` | `false` | Preserve installers on secondary machines after deployment.
| `oneagent_package_state` | `present` | OneAgent package state; use `present` or `latest` to make sure it's installed, or `absent` in order to uninstall.
| `oneagent_reboot_host` | `false` | Reboot the secondary machine after OneAgent installation
| `oneagent_verify_signature` | `true` | Verifies installer's signature (available only on AIX/Linux platforms)
| `oneagent_reboot_timeout` | `3600` | Set the timeout for rebooting secondary machine in seconds
| Name | Default | Description |
| -------------------------------- | -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `oneagent_environment_url` | `-` | The URL of the target Dynatrace environment (see [Direct download from your environment](#direct-download-from-your-environment)). |
| `oneagent_paas_token` | `-` | The [PaaS Token] retrieved from the "Deploy Dynatrace" installer page. |
| `oneagent_local_installer` | `-` | The Path to OneAgent installer stored on the main node. |
| `oneagent_installer_arch` | `-` | Specifies the OneAgent installer architecture. |
| `oneagent_version` | `latest` | The required version of the OneAgent in the `1.199.247.20200714-111723` format. See [Deployment API - GET available versions of OneAgent] for more details. |
| `oneagent_download_dir` | Linux: `$TEMP` or `/tmp`</br>Windows: `%TEMP%` or `C:\Windows\Temp` | Installer download directory. For Linux and AIX, the directory must not contain spaces. Will be created if it does not exist. |
| `oneagent_install_args` | `-` Dynatrace OneAgent installation parameters defined as a list of items. |
| `oneagent_platform_install_args` | `-` | Additional list of platform-specific installation parameters, appended to `oneagent_install_args' when run on a respective platform. |
| `oneagent_preserve_installer` | `false` | Preserve installers on secondary machines after deployment. |
| `oneagent_package_state` | `present` | OneAgent package state; use `present` or `latest` to make sure it's installed, or `absent` in order to uninstall. |
| `oneagent_reboot_host` | `false` | Reboot the secondary machine after OneAgent installation |
| `oneagent_verify_signature` | `true` | Verifies installer's signature (available only on AIX/Linux platforms) |
| `oneagent_reboot_timeout` | `3600` | Set the timeout for rebooting secondary machine in seconds |

For more information, see customize OneAgent installation documentation for [Linux], [Windows], and [AIX].

## Examples

You can find example playbooks in the `examples` directory within the role. The directory contains the following:
-`local_installer` - basic configuration with local installers.
-`advanced_config` - showing advanced configuration with a custom install path and download directory.
-`oneagentctl_config` - showing bare configuration with oneagentctl.
You can find example playbooks in the `examples` directory within the role. The directory contains the following: -`local_installer` - basic configuration with local installers. -`advanced_config` - showing advanced configuration with a custom install path and download directory. -`oneagentctl_config` - showing bare configuration with oneagentctl.

Additionally, each directory contains inventory file with basic hosts configuration for playbooks.

__NOTE:__ For multi-platform Windows, Linux or AIX deployment, you must specify the `become: true` option for proper machines group in the inventory file.
**NOTE:** For multi-platform Windows, Linux or AIX deployment, you must specify the `become: true` option for proper machines group in the inventory file.
On Windows, `become: true` option is not supported.
Since Windows paths are different compared to a traditional Linux system, review [Path Formatting for Windows] to avoid issues during install.

Expand Down
4 changes: 1 addition & 3 deletions roles/oneagent/examples/advanced_config/advanced_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Download OneAgent installer in specific version to a custom directory with additional OneAgent install parameters.
Both linux_other and linux_arm have different user specified by platform args parameter.
hosts: linux_other,linux_arm
collections:
- dynatrace.oneagent
# credentials.yml file contains oneagent_environment_url and
# oneagent_paas_token variables that needs to be stored securely
vars_files:
Expand All @@ -22,4 +20,4 @@
tasks:
- name: Import Dynatrace OneAgent role
ansible.builtin.import_role:
name: oneagent
name: dynatrace.oneagent.oneagent
4 changes: 1 addition & 3 deletions roles/oneagent/examples/local_installer/local_installer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Basic OneAgent installation using a local installer. Hosts placed in unix hosts groups have its local installer paths defined in inventory file.
Main node communicates with Windows hosts over SSH.
hosts: windows,unix
collections:
- dynatrace.oneagent
tasks:
- name: Import Dynatrace OneAgent role
ansible.builtin.import_role:
name: oneagent
name: dynatrace.oneagent.oneagent
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
- name: Apply host level configuration with oneagentctl
hosts: linux_other
collections:
- dynatrace.oneagent
vars:
oneagent_install_args:
- --set-host-name=new_host_name
Expand All @@ -12,4 +10,4 @@
tasks:
- name: Import Dynatrace OneAgent role
ansible.builtin.import_role:
name: oneagent
name: dynatrace.oneagent.oneagent
Loading

0 comments on commit eb04a21

Please sign in to comment.