Giter VIP home page Giter VIP logo

ansible / vscode-ansible Goto Github PK

View Code? Open in Web Editor NEW
319.0 13.0 73.0 19.67 MB

vscode/vscodium extension for providing Ansible auto-completion and integrating quality assurance tools like ansible-lint, ansible syntax check, yamllint, molecule and ansible-test.

Home Page: https://ansible.readthedocs.io/projects/vscode-ansible/

License: MIT License

JavaScript 0.26% TypeScript 91.49% Python 1.12% Shell 2.72% Dockerfile 0.07% CSS 4.33%
vscode-extension ansible-lint molecule ansible-language-server lsp hack hacktoberfest taskfile ansible-dev-tools

vscode-ansible's Introduction

Ansible VS Code Extension by Red Hat

This extension adds language support for Ansible to Visual Studio Code and OpenVSX compatible editors by leveraging ansible-language-server.

Language association to yaml files

The extension works only when a document is assigned ansible language. The following method is used to assign ansible language to the document opened by the extension:

Without file inspection

  • yaml files under /playbooks dir.
  • files with the following double extension: .ansible.yml or .ansible.yaml.
  • notable yaml names recognized by ansible like site.yml or site.yaml
  • yaml files having playbook in their filename: *playbook*.yml or *playbook*.yaml

Additionally, in VS Code, you can add persistent file association for language to settings.json file like this:

{
  ...

  "files.associations": {
    "*plays.yml": "ansible",
    "*init.yml": "yaml",
  }
}

With file inspection

File inspection for ansible keywords

  • Primary method is inspection for top level playbook keywords like hosts and import_playbook in yaml files.

Modelines (optional)

  • The extension also supports the usage of modelines and when used, it is given highest priority and language is set according to modelines. Example and syntax of modelines:
# code: language=ansible
or
# code: language=yaml

Rest all the .yml, or .yaml files will remain yaml by default unless the user explicitly changes the language to ansible for which the process is mentioned below.

Activating Red Hat Ansible extension manually

It is recommended to open a folder containing Ansible files with a VS Code workspace.

Linter support

Note:

  • For Ansible files open in an editor window ensure the language mode is set to Ansible (bottom right of VS Code window).
  • The runtime status of extension should be in activate state. It can be verified in the Extension window Runtime Status tab for Ansible extension.

Features

Syntax highlighting

Syntax highlighting

Ansible keywords, module names and module options, as well as standard YAML elements are recognized and highlighted distinctly. Jinja expressions are supported too, also those in Ansible conditionals (when, failed_when, changed_when, check_mode), which are not placed in double curly braces.

The screenshots and animations presented in this README have been taken using the One Dark Pro theme. The default VS Code theme will not show the syntax elements as distinctly, unless customized. Virtually any theme other than default will do better.

Validation

YAML validation

While you type, the syntax of your Ansible scripts is verified and any feedback is provided instantaneously.

Integration with ansible-lint

Linter support

On opening and saving a document, ansible-lint is executed in the background and any findings are presented as errors. You might find it useful that rules/tags added to warn_list (see Ansible Lint Documentation) are shown as warnings instead.

Smart autocompletion

Autocompletion

The extension tries to detect whether the cursor is on a play, block or task etc. and provides suggestions accordingly. There are also a few other rules that improve user experience:

  • the name property is always suggested first
  • on module options, the required properties are shown first, and aliases are shown last, otherwise ordering from the documentation is preserved
  • FQCNs (fully qualified collection names) are inserted only when necessary; collections configured with the collections keyword are honored. This behavior can be disabled in extension settings.

Auto-closing Jinja expressions

Easier Jinja expression typing

When writing a Jinja expression, you only need to type "{{, and it will be mirrored behind the cursor (including the space). You can also select the whole expression and press space to put spaces on both sides of the expression.

Documentation reference

Documentation on hover

Documentation is available on hover for Ansible keywords, modules and module options. The extension works on the same principle as ansible-doc, providing the documentation straight from the Python implementation of the modules.

Jump to module code

Go to code on Ctrl+click

You may also open the implementation of any module using the standard Go to Definition operation, for instance, by clicking on the module name while holding ctrl/cmd.

Ansible Lightspeed with watsonx Code Assistant

AI based Ansible code recommendations

Requirements

For Windows users, this extension works perfectly well with extensions such as Remote - WSL and Remote - Containers.

If you have any other extension providing language support for Ansible, you might need to uninstall it first.

Configuration

This extension supports multi-root workspaces, and as such, can be configured on any level (User, Remote, Workspace and/or Folder).

  • ansible.ansible.path: Path to the ansible executable.
  • ansible.ansible.reuseTerminal: Enabling this will cause ansible commands run through VS Code to reuse the same Ansible Terminal.
  • ansible.ansible.useFullyQualifiedCollectionNames: Toggles use of fully qualified collection names (FQCN) when inserting a module name. Disabling it will only use FQCNs when necessary, that is when the collection isn't configured for the task.
  • ansible.validation.lint.arguments: Optional command line arguments to be appended to ansible-lint invocation. See ansible-lint documentation.
  • ansible.validation.lint.enabled: Enables/disables use of ansible-lint.
  • ansible.validation.lint.path: Path to the ansible-lint executable.
  • ansible.ansibleNavigator.path: Path to the ansible-navigator executable.
  • ansible.executionEnvironment.containerEngine: The container engine to be used while running with execution environment. Valid values are auto, podman and docker. For auto it will look for podman then docker.
  • ansible.executionEnvironment.containerOptions: Extra parameters passed to the container engine command example: --net=host
  • ansible.executionEnvironment.enabled: Enable or disable the use of an execution environment.
  • ansible.executionEnvironment.image: Specify the name of the execution environment image.
  • ansible.executionEnvironment.pull.arguments: Specify any additional parameters that should be added to the pull command when pulling an execution environment from a container registry. e.g. --tls-verify=false
  • ansible.executionEnvironment.pull.policy: Specify the image pull policy. Valid values are always, missing, never and tag. Setting always will always pull the image when extension is activated or reloaded. Setting missing will pull if not locally available. Setting never will never pull the image and setting tag will always pull if the image tag is 'latest', otherwise pull if not locally available.
  • ansible.executionEnvironment.volumeMounts: The setting contains volume mount information for each entry in the list. Individual entry consist of a
    • src: The name of the local volume or path to be mounted within execution environment.
    • dest: The path where the file or directory are mounted in the container.
    • options: The field is optional, and is a comma-separated list of options, such as ro,Z
  • ansible.python.interpreterPath: Path to the python/python3 executable. This setting may be used to make the extension work with ansible and ansible-lint installations in a Python virtual environment. Supports ${workspaceFolder}.
  • ansible.python.activationScript: Path to a custom activate script, which will be used instead of the setting above to run in a Python virtual environment.
  • ansible.completion.provideRedirectModules: Toggle redirected module provider when completing modules.
  • ansible.completion.provideModuleOptionAliases: Toggle alias provider when completing module options.
  • ansibleServer.trace.server: Traces the communication between VS Code and the ansible language server.
  • ansible.lightspeed.enabled: Enable Ansible Lightspeed.
  • ansible.lightspeed.URL: URL for Ansible Lightspeed.
  • ansible.lightspeed.suggestions.enabled: Enable Ansible Lightspeed with watsonx Code Assistant inline suggestions.
  • ansible.lightspeed.suggestions.waitWindow: Delay (in milliseconds) prior to sending an inline suggestion request to Ansible Lightspeed with watsonx Code Assistant.
  • ansible.lightspeed.modelIdOverride: Model ID to override your organization's default model. This setting is only applicable to commercial users with an Ansible Lightspeed seat assignment.
  • ansible.lightspeed.disableContentSuggestionHeader: Do not include code comment crediting Ansible Lightspeed when accepting a Lightspeed suggestion.

Data and Telemetry

The vscode-ansible extension collects anonymous usage data and sends it to Red Hat servers to help improve our products and services. Read our privacy statement to learn more. This extension respects the redhat.telemetry.enabled setting, which you can learn more about at https://github.com/redhat-developer/vscode-redhat-telemetry#how-to-disable-telemetry-reporting

Known limitations

  • The shorthand syntax for module options (key=value pairs) is not supported.
  • Nested module options are not supported yet.
  • Only Jinja expressions inside Ansible YAML files are supported. In order to have syntax highlighting of Jinja template files, you'll need to install other extension.
  • Jinja blocks (inside Ansible YAML files) are not supported yet.

Contact

Credit

Based on the good work done by Tomasz Maciążek

vscode-ansible's People

Contributors

ansibot avatar audgirka avatar clwluvw avatar dependabot[bot] avatar egnirra avatar elyezer avatar fgierlinger avatar florianlaunay avatar fredericgiquel avatar ganeshrn avatar garymm avatar gebhardtr avatar github-actions[bot] avatar goneri avatar hasys avatar imgbot[bot] avatar jeinwag avatar justjais avatar kimbernator avatar manstis avatar pre-commit-ci[bot] avatar priyamsahoo avatar robinbobbitt avatar romartin avatar samccann avatar ssbarnea avatar tamitakamiya avatar tomaciazek avatar webknjaz avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vscode-ansible's Issues

Ansible schemas not loaded

I am currently trying to use this module, but I have an error:

Problems loading reference 'https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-tasks.json': Unable to load schema from 'https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-tasks.json': No content.

The quick traffic debug show that server return
"304 - not modified" on load request
Cache clearing dit not help

I see two non-exclusive solutions:

  • make schema path configurable
  • use 'do not cache' headers on request

[ansible-language-server] Add task completion name to work with collection completions.

Problem

Add task completion name to work with collection completions. Currently module name completion is supported. Installing a new collection from galaxy user would except to provide completion for collection name while fully qualified names for plugins.

Solution

Update ansible-language-server to parse collection name and provide as completion item in client reponse.

Alternatives

No response

Additional context

No response

WSL Support missing?

Hi,

i hate to be that guy but this extension isn't working for me at all.
I have the suspicion that the fact that I'm using WSL isn't helping either.
When i'm running vscode inside the WSL environment via the "Remote" feature, nothing happens when i save the file.
When i'm running it "normally" on Windows it obviously complains that the path to ansible-lint is invalid because i only installed it inside WSL.

Do not ask for vault id during encryption if only one is configured

Is your feature request related to a problem? Please describe.
Not a problem but a lack of UX: you are asked to choose a vault id even if only one is configured

ask_vault

Describe the solution you'd like
Not to be asked if only one vault id is configured

Describe alternatives you've considered
.

Additional context
.

Add dedicated output channel

Hi, I recently installed the extension and so far it's exactly what I needed; thanks for your work!

I really think that the extension should register a dedicated channel to log its events. It would also help in solving errors (e.g. by logging the ansible-lint invocation output)

It currently only logs this message to the vscode extension host channel:

https://github.com/ansible-community/vscode-ansible/blob/103e7208d78b6ecaef205bf98d9c2c172d55f2ea/src/extension.ts#L12

It should be doable relatively easily by using this:

https://code.visualstudio.com/api/references/vscode-api#window.createOutputChannel

And using the resulting OutputChannel.appendLine(...) method.

I'd be really interested in helping directly but I have exactly zero experience in developing vscode extensions.

Add support for generic playbook directory structure

Currently this plugin expects you to have ansible yml files in the following directory structure:


      {
        "fileMatch": "requirements.yml",
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-requirements.json"
      },
      {
        "fileMatch": "meta/main.yml",
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-meta.json"
      },
      {
        "fileMatch": ["vars/*.yml", "defaults/*.yml", "host_vars/*.yml", "group_vars/*.yml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-vars.json"
      },
      {
        "fileMatch": ["tasks/*.yml", "handlers/*.yml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-tasks.json"
      },
      {
        "fileMatch": ["playbooks/*.yml", "playbooks/*.yaml"],
        "url": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-playbook.json"
      }

If you have your playbook in another folder, say ansible/main.yml it will not match. This should be worked around to implement a broader match for valid ansible yml files.

Schema verification of inline !vault results in "unknown tag"

Issue: !vault | results in unknown tag

Encrypting individual variables in an inventory results in schema errors. Relevant docs for ansible vault:

https://docs.ansible.com/ansible/latest/user_guide/vault.html#encrypting-individual-variables-with-ansible-vault

Here's an anonymized snippet from my ansible inventory:

snmp:
  addresses:
    - "10.44.16.10"
  rocommunity: !vault |
    $ANSIBLE_VAULT;1.1;AES256
    31353063366434366235343939393130626666383561336638613963633636393962656231646536
    3237316430363038303632383464653432336534666336340a333262653237396137623564343630
    38656561323031356265653964653238633636393832643062356338666538303431333337653033
    3836666439393132300a383633376465366130356237633439323639353335383338333465343935
    33663861333232663865316237656138373133393461333733313639383733391234

And screenshot from VS Code ansible extension showing issue (https://github.com/ansible-community/vscode-ansible):

Screenshot 2021-05-07 at 11 07 25

Wrong yaml schema for group_vars?

i have opened a Folder containing a playbook in vscode.
inside a subfolder named group_vars i have all.yml containing some variables.

vscode-ansible complains about the format because it uses the "Ansible Playbook Schema" for some reason:
image

i saw you have set yamlValidation accordingly in your package.json so i don't know what is happening here.

Autocomplete not working properly in tasks file within role

Autocomplete is not working properly when I'm editing a tasks file within a role, I only get suggestions for generic task parameters:

image

It does work in a top-level playbook however:

image

To Reproduce
Create a new role and start editing a tasks file.

Expected behavior
I expect to get full autocomplete suggestions when editing the tasks file.

Platform:

  • OS: macOS 11.4
  • VSCode: Version: 1.58.1 Commit: 2aeda6b18e13c4f4f9edf6667158a6b8d408874
  • Ansible Language Extension 0.4.5

Allow to set custom PATH for the execution of this extension

Please see my comments here: #129 (comment)

This extension allows to configure the path to the ansible-lint executable, but this is not enough. ansible-lint calls the ansible executable and expects this to be on the global PATH:

https://github.com/ansible-community/ansible-lint/blob/57a6d5bd1cb5fb85fdda040d0165d8a75c8f43f1/src/ansiblelint/config.py#L146

The same is probably true for the execution of yamllint.

So, what's the point of configuring the full path to ansible-lint if ansible and yamllint are expected to be on the global PATH? Why not just make the same assumption for the ansible-lint executable?

Instead of (or in addition to) making ansible.validate.executablePath and ansible.vault.executablePath configurable, I think it would be better to have another setting to configure a custom PATH that is valid for the whole extension and is also used when ansible-lint calls ansible (as shown above).

This setting could be called something like ansible.path and should be configurable per-workspace and per-folder, so that is can be adjusted for local venv or conda-environments. The value of this setting should be used instead or (probably better) be prepended to the global PATH of the vscode process.

As described in #129 (comment), setting a custom PATH when calling ansible-lint fixes the issue where ansible and yamllint are not on the global PATH.

fileMatch paths do not follow official Ansible code layout guidelines

In README.md it says filepaths should follow the official Ansible code layout guidelines. Clicking on the link and this structure comes up:

collection/
├── docs/
├── galaxy.yml
├── meta/
│   └── runtime.yml
├── plugins/
│   ├── modules/
│   │   └── module1.py
│   ├── inventory/
│   └── .../
├── README.md
├── roles/
│   ├── role1/
│   ├── role2/
│   └── .../
├── playbooks/
│   ├── files/
│   ├── vars/
│   ├── templates/
│   └── tasks/
└── tests/

But this does not work because package.json defines other paths.

Solution is to change package.json or suggest another file structure that matches paths defined in package.json

After the last issues in a file reported by ansible-lint are fixed, those still get shown

Describe the bug

After the last issue(s) within a .yml file reported by ansible-lint are fixed and the file saved, the issue(s) still gets shown inside the editor as well as the problems list, until the the file gets closed.

To Reproduce

Steps to reproduce the behavior:

  1. Open a .yml file with one or more issues reported by ansible-lint
  2. Fix all the issues and save the file
  3. See the issues fixed in step 2 still present in the problems list of VSCode as well as in the editor
  4. Close the file. Watch issues disappearing from the problem list

Example playbook for testing

- hosts: localhost
  vars: 
    testvar: "hello"
  tasks:
    - name: "test one {{testvar}}"
      debug:
        msg: "this is a test"

Expected behavior

The issues should not be shown any longer after the issues get fixed and the file gets saved, without having to close the file.

Platform:

tested on Fedora Linux and Windows 10

test system 1: Windows

Version: 1.56.0 (system setup)
Commit: cfa2e218100323074ac1948c885448fdf4de2a7f
Date: 2021-05-04T22:09:06.405Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Windows_NT x64 10.0.19042

remote ssh is used to connect to a Debian 10 system
ansible-lint 5.0.8 using ansible 2.10.9 on the remote system

test system 2: Fedora

Version: 1.56.0
Commit: cfa2e218100323074ac1948c885448fdf4de2a7f
Date: 2021-05-04T21:58:14.757Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Linux x64 5.11.18-300.fc34.x86_64

working on local files
ansible-lint 5.0.8 using ansible 2.10.9

Both test systems show the same behavior.

Additional context

When fixing the issues one by one and saving in between, the fixed issues get removed from the problem list as excepted. This only happens if there are no further issues found in the file.

No support for yamllint yet?

The README states:

Display violations identified by ansible-lint, ansible own syntax check and yamllint inside problems tab.

The VSCode extension description states:

Ansible YAML schema verification, auto-complete, highlight problems reported by ansible-lint or yamllint and vault encryption and decryption.

But I cannot find any support for yamllint. In fact, when I search this repo for the word yamllint, the only matches are in text files.

Is this feature yet to come?

Edit: I know this sounds like a "feature request", but I've posted this as a "bug" because the current project descriptions advertise a feature that may not be there. In this case, I think this is a "bug" in the descriptions.

Error cannot be correlated with ansible-lint output

Describe the bug

This screenshot should demonstrates all the problem. It can be seen that the error report from VSCode cannot be correlated with the ansible-lint output at all.

Screenshot from 2021-08-01 16-27-01

The output should be:

parser-error: conflicting action statements: set_fact, dmmy
tasks/iptables.yml:2

yaml: too few spaces before comment (comments)
tasks/iptables.yml:88

yaml: too few spaces before comment (comments)
tasks/iptables.yml:89

but the error list is empty

Expected Behavior

VSCode plugin should use ansible-lint output

Current Behavior

It does not

Steps to Reproduce

  1. git checkout https://github.com/kyl191/ansible-role-openvpn
  2. open it with VSCode/ ansible plugin
  3. add a random non-existing field to any task
  4. save and observe both outputs

Environment

  • Windows
  • Mac
  • Linux
  • other (please specify)

Support password clients to edit vaulted files/data

ansible-vault supports executing programs, passing them --vault-id $vault_id. I see 2 ways this could be solved:

  1. user interaction required: ask the user for the vault-id string in a popup (user enters vault-name@$whatever)
    • if $whatever is prompt, prompt for the password interactively
    • if $whatever isn't prompt, use it as is
  2. no user interaction required: let the user configure the right part of the vault-id (be it a file or a password client) and try to detect the vault name from the file, construct the vault-id based on that, if it doesn't work, fall back to 1.

Report if ansible-lint is broken

As ansible-lint have very special requirements for running, we need to be sure that we run ansible-lint --version and report any potential error in a visible way in the UI.

This should make it easier for users to debug broken or incomplete installs of ansible-lint tool.

Related: ansible/ansible-lint#1507

Find others to join the efforts

I am looking for others to join my effort of building a vscode extension for Ansible content creators. The project is in planning phase and installing the extension does not enable any features yet.

I would not have started yet-another-extension endeavor unless I would have found one to contribute to. It would worth mentioning existing related extensions:

  • vscode-yaml extension provides schema verifications for YAML in a generic way. We are going to rely on it in order to enable Ansible schema, this extension can be seen as a dependency.
  • ansible (ms) is an old Ansible extension developer by Microsoft China team which is currently unmaintained and which is not compatible with other YAML extensions, making it pretty much useful in practice.

As my JavaScript/TypeScript skills are not listed on my resume, I would likely progress very slow on this task and I will likely need help, especially for building the initial version. I am sure maintaining it will be much easier after we get the basics done.

If you want to help or know someone that could, please post a message. Thanks!

Can't use variable when schema define something as boolean

Describe the bug
When something is define as boolean in the schema, like ignore_errors when the value is set by a variable, vscode show an error telling Incorrect type. Expected "boolean".yaml-schema: BeremothTaskModel, even with the filter bool to force the type of the variable.

To Reproduce
Create a task like:

- name: "Demo error"
  fail:
    msg: fail except in check mode
  ignore_errors: "{{ ansible_check_mode | bool }}"

Expected behavior
No error about the type, at least when the type is forced (if | bool is specified this trigger a warning in the default configuration of ansible-lint, not without, so it'll be better if this isn't needed).

Platform:
Be sure vscode and extension are the latest versions and report here the
operating system you used. If you used remote-ssh or WSL. Please check if the
bug can be reproduced on Linux or MacOS.

  • OS: Archlinux

Use codeclimate output format instead of pep8 for ansible-lint

The codeclimate output format is JSON and includes information that is not part of the brief pep8 format, like the multiline description of the error, which sometimes contains critical information about how to fix it.

We only need to swap our parser and call the linter with -f codeclimate instead of -p.

Add support for editing vaults

As the title probably needs not more explanation, I should mention that there are already 4 extensions on vscode marketplace related to vault editing. Looking at them I noticed a pattern where almost each of them seems to be a fork of a previous one. I suspect what caused it is that original creator lost interest in maintaining it.

Instead of cluttering the marketplace with yet another extension that aims to address the same issue, I am inclined to see if one of the authors of these extensions is willing to join efforts and transition this feature into our extension, so we can have less extensions but better maintained.

Identified extensions:

Vaulting use-cases

There are lots of way of working with secrets in Ansible and we will not be able to cover all from start, still we should document each one we identify and mention if they are supported or not, also allowing us to create tests for them later.

  • single vault defined inside ansible.cfg: vault_identity_list = .pass or alternatives that can use names like [email protected] or [email protected]. Ansible encrypts and decrypts files without any prompts in this case, it does not expect passsing a vault id.
  • multiple vaults defined inside ansible.cfg: vault_identity_list = [email protected] [email protected]. Ansible will try to guess decryption key to use if the encrypted text does not mention the name. Still encrypting requires mentioning the vault id.
  • no vault_identity_list defined but ansible_password_file is defined, which points to the file with the secret.
  • vault files that are executable ... (TBD)

The top element in the inventory is highlighted with an error

Describe the bug

The top element in the inventory is highlighted with an error

To Reproduce
Steps to reproduce the behavior:

  1. Create an inventory.yml in root directory
  2. Fill inventory and open it
  3. See this error at the top element:
A playbook must be a list of plays, got a <class 'ansible.parsing.yaml.objects.AnsibleMapping'> instead

Expected behavior
Inventories should not be treat as playbooks.

Platform:

VS Code: 1.56.2
Ansible Language Extension: v0.4.5
OS: macOS Big Sur 11.4
Ansible: 2.11.0

Adopt ansible-language-server

Basically this task is about refactoring this extension to make use of https://github.com/ansible/ansible-language-server instead of YAML/JSON schema.

Checklist for releasing the rewritten version

  • playbooks/tasks/vars/requirements/molecule files are still recognized and basic syntax errors recognized
  • ansible-lint is working (at least when installed in path)
  • can coexist with Red Hat YAML extension, in fact we can even keep the current dependency on it as it does provide support for schemas that we are unlikely to do ourselves (zuul, molecule, ansible-lint config).

@tomaciazek will have the pleasure to lead that purge ;)

Bad file hinting when using include_tasks

Hi guys,

I am now using your plugin in version 0.3.0 and I really thanks you.
I just discovered an issue when there are a lint warning/error in a file that is included with include_tasks.

Let's see the main.yml file :

---
- name: Pre-processing checks
  include_tasks: pre-check.yml

Now, here is the pre-check.yml that has an indentation lint error on the last line, to trigger the lint message in the console :

- name: pre-check| clients list is empty
  fail:
    msg: "clients list is empty, please check configuration..."
  tags:
  - generate-rules

Ok so, let's see what the linter says :

image

Regarding the error message, it seems that there is something bad on line 5 within main.yml. Actually, the error message is into the pre-check.yml included file.

Thanks guys !

Wrong file links in problems pane

Describe the bug
After installing this extension, I get "problems" reported about YAML files, but they reference files with a weirdly relative link that make them not clickable.

To Reproduce
Steps to reproduce the behavior:

  1. Install the extension
  2. open an editor with YAML files that include syntax errors
  3. look at the "problems" pane
  4. file links are relative (with bad reference) and not absolute

For example, I get links like home/jlecour/ansible/playbook.yml instead of /home/jlecour/ansible/playbook.yml.

Expected behavior
File links should be clickable.

Version: 1.56.0
Commit: cfa2e218100323074ac1948c885448fdf4de2a7f
Date: 2021-05-04T21:58:14.757Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Linux x64 4.19.0-16-amd64

ansible.cfg is not used if it is not the root of the project

Describe the bug

For example, there is a tree like this:

infra
├── README.md
├── ansible
│   ├── ansible.cfg
│   ├── group_vars
│   ├── .vault
│   ├── inventory.ini
│   └── playbooks
└── infra.code-workspace
# ansible.cfg
[defaults]
inventory=inventory.ini
[email protected]

If the ansible directory is in a subdirectory of project, vscode-ansible simply doesn't see it. As a result, the extension.ansible.vault command doesn't work, because it can't find the vault_identity_list setting.
If you run vscode from the subdirectory ansible, it works fine.

Maybe a feature should be added to specify the path to ansible.cfg and the extension.ansible.vault function will work relative to that path, or something like that. It's not really convenient to have to run an instance of vscode separately in the ansible directory in a large project to make encryption/decryption work on the fly.

Add packaging and publishing pipeline

In order to ease development and maintenance of this extensions we need to automate the packaging and publishing, making easy to make a new release just by using the release github feature.

  • discover if there is an already existing action we can reuse (considering openvsx store too)
  • action to package
  • fail if current version from package.json was already release (tag existing or already uploaded)
  • add PAT tokens
  • publish on tags

Getting error when specify ansible-lint executable in WSL2

Describe the bug
Well i dont know if its a bug but i followed the guide to install lint but still getting error when typing in the path of ansible-lint in config file

ansible-lint is installed in my /.local/bin/ansible-lint
PATH is also correct as i can execute the ansible-lint from anywhere
what else can be wrong ?

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Platform:

im running WIndows 10 with WSL2 and Ubuntu 20.04

Additional context
Add any other context about the problem here.

Add e2e integration testing for extension

Is your feature request related to a problem? Please describe.

No tests.

Describe the solution you'd like

Tests must exist.

Describe alternatives you've considered

Giving up on quality.

Additional context

There's not many good examples of writing integration tests for VS Code extensions so here's some pointers I've found:

Implement auto-installation of ansible-lint

Extension code should detect absence of ansible-lint executable and to prompt user to install the missing dependency.

I am not sure exactly how to implement it so, if someone can point to a similar example where is this is done, it would be awesome, or even better make a pull-request ;)

Integrate ansible-lint

We need to display rule violations reported by ansible-lint inside the "problems" panel.

Things to consider:

  • Running ansible-lint on single files is unreliable because it needs to look at the entire repository in order to detect which files are Ansible owned or not and even after doing so, they cannot be parsed in isolation (content of one file may produce an error in another file).
  • We should try to avoid adding our own language server, we should make use of YAML.
  • Finding a sample code that produces these problems could prove very useful

Extension is running ansible-lint on all yaml files, causing high CPU usage

This extension is spawning tons of Python processes by running ansible-lint on all yaml files in all projects, including kubernetes manifests, etc. Results in huge CPU usage and high load. Found by running pgrep -fl Python after opening some k8s project.

Fixed for now by "ansible.validate.enable": false in settings.json.

Could it be configured to run lint only on 'ansible' files and not on all yaml?

I've noticed that extension is not "defining" 'ansbile' language in package.json, as in now deprecated vscoss.vscode-ansible extension but rather extending 'YAML' language, might that be root of this issue? Or it's just some misconfiguration on my system?

I'm happy to provide any additional info if needed.

VSCode: 1.55.0
zbr.vscode-ansible: v0.3.0
OS: MacOS 11.2.3

Extension apparently inactive after install

Hi,

Here is my setup :

Version: 1.56.0
Commit: cfa2e218100323074ac1948c885448fdf4de2a7f
Date: 2021-05-04T21:58:14.757Z
Electron: 12.0.4
Chrome: 89.0.4389.114
Node.js: 14.16.0
V8: 8.9.255.24-electron.0
OS: Linux x64 4.19.0-16-amd64

I've just installed and enabled the extension (and event restarted VS Code), but the extension seems to remain inactive.
My playbooks/roles/… are still treated as YAML and Ansible is not in the list of possible languages.

Did I miss something?

Switch publisher to Red Hat

While I developed this extension I do think it would be much better to publish it from either already existing Red Hat publisher or by creating a new Ansible, or Ansible Community publisher, one where @gundalow will also be fallback admin.

I am personally inclined to find the Red Hat publisher better because it would send a very good positive message about Red Hat contributions in general.

In fact, I would not even mind to transfer the github repository to @redhat-developer github organization if that is required.

My personal take is is may be better to keep it under @ansible-community because here are all the Ansible specific knowledge is involved and I expect that most contributors are likely to know more about Ansible than about JavaScript.

Obviously that we first need to find-out if Red Hat folks are going to welcome us.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.