Boat
Boat

Reputation: 529

Ansible Get dict value from key

I have two files, one with 2 dict and another playbook that use those dict.

Vars file:

data: {path: ~/prod/iac/playbook/test.conf, conf: test2} vagrant: {path: ~/prod/iac/playbook/test.conf/test2.conf, conf: test4}

and the playbook:

--- - hosts: localhost tasks: - name: Include var for nginx config include_vars: file: ~/prod/iac/playbook/vars.yml name: conf_vars - name: overide doc configuration shell: echo "{{ item[path] }}" > test.conf with_items: " {{ conf_vars }}"

My vars is correctly loaded but i can't get the dict value... Any idea ?

Upvotes: 0

Views: 3614

Answers (1)

Konstantin Suvorov
Konstantin Suvorov

Reputation: 68229

conf_vars is a dictionary, with_items is to be used with lists.

You may want to use with_dict:

- name: overide doc configuration
  shell: echo  "{{ item.value[path] }}" > test.conf
  with_dict: "{{ conf_vars }}"

Upvotes: 1

Related Questions