Datum Geek
Datum Geek

Reputation: 1568

vs-code editor for yaml says expecting a map but found a sequence

i'm editing a main.yml in an ansible role's tasks folder.

i'm using the YAML vscode extension by Red Hat.

Here's the first part of the file...

# Install Packages
- name: Install the Kafka Broker Packages
  yum:
    name: "{{item}}-{{confluent.package_version}}"
    state: latest
  loop: "{{kafka_broker_packages}}"
  when: ansible_os_family == "RedHat"

- name: Install the Kafka Broker Packages
  apt:
    name: "{{item}}={{confluent.package_version}}"
    update_cache: yes
  loop: "{{kafka_broker_packages}}"
  when: ansible_os_family == "Debian"

the entire file has the red squiggly underline saying:

Expecting a 'map', but found a 'sequence'

i'm sure i'm doing something silly - any help is greatly appreciated

Upvotes: 1

Views: 7017

Answers (4)

Jehad Nasser
Jehad Nasser

Reputation: 3555

Go to File >> preferences >> settings then in the top-right corner click open settings(json) icon. Then add this inside the settings' json:

"files.associations": {
   "**/*.yml": "yaml"
}

Upvotes: 1

MinhTC
MinhTC

Reputation: 475

The cause of this issue is that the ansible extension (https://marketplace.visualstudio.com/items?itemName=vscoss.vscode-ansible) doesn't recognize the given file as its supported item. To get rid of it, try editing the settings.json of VSCode to add the following configuration:

"files.associations": {
    "**/*.yml": "ansible"
},
"ansible.validation": true

Upvotes: 7

JPinkney
JPinkney

Reputation: 11

VSCode-YAML pulls in JSON schemas from http://schemastore.org/json/ and tries to associate schemas with yaml files so that you can have hover, auto completion, validation without any configuration on your side. However, sometimes these schemas are incorrect, which seems to be the case here.

You can file an issue here: https://github.com/SchemaStore/schemastore and any update to the schema there will appear in vscode-yaml or you can disable the schema store by setting "yaml.schemaStore.enable" to false.

Upvotes: 0

flyx
flyx

Reputation: 39718

Well the Readme of that extension says:

with built-in Kubernetes and Kedge syntax support.

So chances are the extension tries to validate your YAML file against a Kubernetes or Kedge schema, which fails since you're writing a configuration file for Ansible. You can try setting yaml.validate to "false" to disable validation.

However, you are probably better off using the Ansible extension instead.

Upvotes: 2

Related Questions