Steampunk Spotter Visual Studio Code Extension: Setup and scanning

July 4, 2023 - Words by  The Spotter team - 3 min read

This blog post explores the Visual Studio Code (VSC) extension of Steampunk Spotter, a powerful platform that helps you identify and fix errors in your Ansible content, making automation more reliable, secure, and effective.

You can install the extension from the Visual Studio Marketplace or Open VSX Registry. The extension requires a Spotter user account and the Spotter CLI installed in the console that you use with VS Code by default.

Let’s dive into the setup and scanning process.

Settings

Retrieving the CLI path: To begin, you can use the terminal command, which spotter, to retrieve the path to the Spotter CLI. This step ensures a seamless integration.

VS Code settings showing the Spotter CLI path retrieved with the which spotter command

Customizing the URL: If using an on-prem Spotter instance, you can customize the URL through the provided field.

Spotter extension setting for the API endpoint URL in VS Code

API token: You can fetch the token from the Spotter app under “My Settings” in the “Profile settings” section. Once obtained, copy the API token into the corresponding field in the extension’s settings.

Spotter extension setting with the API token field filled in

Scan level configuration: You can set the path to the configuration file (JSON/YAML).

Spotter extension setting for the scan configuration file path

Project ID: You can organize your scans according to project IDs. You can find the ID in the Spotter app. Copy the project ID into the designated field in the extension’s settings.

Spotter extension setting with the project ID field filled in

Ansible version: You can select the Ansible version against which you want to scan. This option allows you to align the scanning process with your specific Ansible environment.

Spotter extension setting for selecting the target Ansible version

Exclude Values: Omit parsing and uploading values from Ansible Playbooks.

Spotter extension checkbox to exclude values from Ansible playbooks

Exclude Metadata: Omit collecting and uploading metadata, i.e., file names, line, and column numbers.

Spotter extension checkbox to exclude metadata such as file names and line numbers

Display level: The display level determines the level of scans. For example, setting it to “warning” will suppress hints.

Spotter extension setting for the scan display level

Scanning Profile: Spotter offers default, full, and security scanning profiles. The default profile covers basic scanning needs, while the full profile provides a more exhaustive scan. The security profile offers additional recommendations and advice on crafting secure playbooks. 

Spotter extension scan profile dropdown with default, full and security options

Skipping Checks: If you want to skip specific checks, you need the ID of the check you wish to omit. You can find the check ID in the check catalogue within the Spotter app. Add the check ID to skip it during the scanning process.

Spotter extension setting for adding check IDs to skip

Enforcing Checks: If you want to enforce specific checks, you need the ID of the check you wish to enforce. You can find the check ID in the check catalogue within the Spotter app. Add the check ID to enforce it during the scanning process.

Spotter extension setting for adding check IDs to enforce

Scanning a playbook

Now that the Spotter extension is set up let’s proceed with how to scan a playbook. You right-click and choose “Initiate a new scan.”

VS Code context menu with the Steampunk Spotter: Initiate a new scan option

Upon completion, Spotter will provide you with a list of identified errors and links to the module documentation.

Spotter scan results listing errors, warnings and hints in the VS Code Problems panel

Automatic fixing

Spotter offers a rewrite function that can automatically fix many errors. Use this feature to address the identified issues. Once applied, the errors will be resolved, and the playbook will be updated accordingly.

VS Code context menu with Steampunk Spotter: Rewrite files with fixes and the fixed playbook

Scanning a directory structure

Extend the scanning process to the entire directory structure. Spotter will scan multiple files within the specified directory and identify any errors.

Spotter scan of a whole directory started from the VS Code explorer context menu

Automatic scanning on file save

Spotter allows you to automatically scan your files after they are saved to streamline the scanning process, ensuring prompt error detection. If you make a mistake in the code, and save the file, Spotter will immediately notify you of any errors found.

Spotter extension setting to scan YAML files automatically on save

Using Spotter in Windows Subsystem for Linux (WSL)

Easily run Steampunk Spotter on your WSL playbooks using Visual Studio Code, bringing together Windows convenience and Linux power in one go.

Your Visual Studio Code has to run in WSL. To use WSL within VS Code, just open Visual Studio Code, hit the Open a Remote Window icon at the bottom left, and choose Connect to WSL from the top menu. You’ll be all set to use Linux tools and files right from VS Code!

VS Code Open a Remote Window menu with the Connect to WSL option highlighted

Pop the Steampunk Spotter extension into your WSL via VS Code — no local installs, please, because they will not work. Need a hand? Check out the guide here. And don’t forget, the Spotter CLI should be installed in your chosen WSL distribution too.

Watch this video to follow the installation process step by step.

Speed up playbook writing with Assisted Playbook Writing feature

The Spotter VSC extension not only offers enhanced scanning abilities but offers an Assisted Playbook Writing feature that you can explore in this blog post or watch this short demo.

Animated demo of Spotter assisted playbook writing in VS Code

Get a free, expert-led review of your Ansible Playbooks - Register for Assessment

Found this post useful?

Get our monthly newsletter.

Thank you for subscribing!

Please wait

Processing, please wait...

Keep up with what we do on our social media.