I have this task in my playbook:
- name: Update instance tags
command: oci compute instance update -c {{ compartment }} --freeform-tags {{ tag_var_json }}
According to the oracle documentation for this command, the parameter --freeform-tags
accepts a json that represents the key-value pair for the tag. I need to have this json be created dynamically in the playbook itself, so prior to running that task, I have this one for testing purposes:
- name: Create a json object to use as tag
set_fact:
tag_var: '{ "test": "thisisatest" }'
set_fact:
tag_var_json: "{{ tag_var | to_json }}"
But I must be doing something wrong because I keep getting this error:
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'tag_var' is undefined
Is there an easier way of creating a json directly in the playbook and passing it as an argument to that parameter?
Thank you.