Skip to content

Ansible Extension crashes if you add a jinja expression (e.g. variable) to hosts field in playbook #2029

@jdratlif

Description

@jdratlif

Summary

If I create a playbook, and add a jinja expression to the hosts field, such as setting the hosts field to a variable possibly with a default, from then on, the ansible extension is unresponsive. I no longer get suggestions for the modules (i.e. I start writing ping and am not given the suggestion ansible.builtin.ping), the colors no longer get syntax highlighting. The extension appears to have crashed entirely and it will not start working until I reload the VS code window.

If the hosts field already has a valid jinja expression and I don't touch it, the extension works fine. It just crashes the first time you make a jina expression in a hosts field.

It doesn't matter if I close the playbook file and reopen, or try to open any other playbook or ansible file. Once you add a jinja expression to the hosts field in a playbook, the extension completely stops working.

---
- name: Test playbook
  hosts: all
  gather_facts: false
  tasks:
    - name: Ping
      ansible.builtin.ping:

The above is fine. No problems.

---
- name: Test playbook
  hosts: "{{ targets | default('all') }}"
  gather_facts: false
  tasks:
    - name: Ping
      ansible.builtin.ping:

I change it to this, and the extension will crash. If I add another task, and start typing debug, I won't get the debug suggestion and the name field will not be highlighted in the correct color.

This is not a recent problem. It has been happening to me for at least a year, probably longer.

Extension version

25.4.0

VS Code version

1.100.2

Ansible Version

$ ansible --version
ansible [core 2.16.12]
  config file = /workspace/.devcontainer/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.11/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.11.5 (main, Nov 15 2023, 18:13:17) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20.0.1)] (/usr/bin/python3)
  jinja version = 3.1.4
  libyaml = True

OS / Environment

Windows 11
Oracle Linux 8
ansible-lint 24.9.2
python 3.11

Relevant log output

I see Ansible Vault, Lighspeed, and Support. I see nothing in Output that says 'Ansible Server'. Am I looking in the wrong place?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions