vscode syntax highlighting

46 views
Skip to first unread message

Matt Warren

unread,
Apr 11, 2021, 3:20:05 PM4/11/21
to Ansible Project
I recently got around to uninstalling the old MS ansible extension and installing the new one. First thing I noticed is the syntax highlighting seems weaker. I've had all sorts of ansible and yaml extensions installed, so I'm not sure if it's me and my config or features yet to be implemented.

Is there schema config I'm missing? 

The old one:
ms-ansible.png

the new one:
new-ansible.png

Govind C

unread,
Apr 11, 2021, 10:58:45 PM4/11/21
to ansible...@googlegroups.com
I am trying to do the following.
I have a variable yaml 

eg:
group_vars.yml
G1:
 - groupname: A
G2:
  groupname: B
G3:
 groupname: C
G4:
 groupname: D

I have this task and I want to pass just the G1 and G2 as extra_vars to the "groups_name" from the command line. How do I go about doing it?
- include_vars: group_vars.yml
- name: Create Group(s)

  group:

    name: "{{ item.groupname }}"

    state: present

  with_items:

     - "{{groups_name}}"



Cheers



Vladimir Botka

unread,
Apr 11, 2021, 11:52:39 PM4/11/21
to Govind C, ansible...@googlegroups.com
On Sun, 11 Apr 2021 22:58:20 -0400
Govind C <gov...@gmail.com> wrote:

> group_vars.yml
> G1:
> - groupname: A
> G2:
> - groupname: B
> G3:
> - groupname: C
> G4:
> - groupname: D
>
> ... pass just the G1 and G2 as extra_vars to "groups_name" from the command line.
> - include_vars: group_vars.yml
> - name: Create Group(s)
> group:
> name: "{{ item.groupname }}"
> state: present
> with_items:
> - "{{groups_name}}"

Put the data into dictionaries, e.g.

shell> cat group_vars.yml
G1:
groupname: A
G2:
groupname: B
G3:
groupname: C
G4:
groupname: D

Include the variables into a dictionary and extract the keys, e.g.

- include_vars:
file: group_vars.yml
name: d1
- debug:
msg: "{{ item.groupname }}"
loop: "{{ groups_name|
default([])|
map('extract', d1)|
list }}"

The command

shell> ansible-playbook pb.yml -e '{"groups_name": ["G1","G2"]}'

should give

msg: A
msg: B

If you have to keep the data in the lists select the the first item

msg: "{{ item.0.groupname }}"

--
Vladimir Botka
Reply all
Reply to author
Forward
0 new messages