1

I want to make a variable named as value of _id. And it seems to be working fine (tested on _id value i know), except I have no clue how to deal with it via _id field.

- name: Set fact
  set_fact: 
    "{{_id}}": "{{ _name }}"
Nav
  • 78
  • 10
  • 3
    it has already been answered at [https://stackoverflow.com/questions/38143647/set-fact-with-dynamic-key-name-in-ansible](https://stackoverflow.com/questions/38143647/set-fact-with-dynamic-key-name-in-ansible) – Oliver Gaida Mar 27 '20 at 15:57

1 Answers1

0

You can do this with the set_fact module, you just have to change your syntax up a bit to reference the metadata in a dictionary for the variable.

- set_fact: {"{{ item.key }}":"{{ item.val }}"}
  loop: "{{ item }}"
  loop_control:
    loop_var: item

Let me know if you have any questions or need any additional help. Happy to assist if I can. Ansible is fun. :)

TJ Zimmerman
  • 3,100
  • 25
  • 39