Last active
December 23, 2024 18:40
-
-
Save hatsari/28b501020ebd6e8b4c0229e6bb2b6291 to your computer and use it in GitHub Desktop.
ansible replace the value of dictionary variable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
### ref: https://stackoverflow.com/questions/48825583/in-ansible-how-do-you-change-a-existing-dictionary-hash-values-using-a-variable | |
- name: replace the value of dictionary variable | |
hosts: localhost | |
gather_facts: no | |
vars: | |
fact_process: | |
cmd_check: ok | |
cmd_name: node1 | |
cmd_status: error | |
tasks: | |
- name: print variables | |
debug: | |
var: fact_process | |
- name: change value | |
set_fact: | |
fact_process: "{{ fact_process | combine(new_item, recursive=true) }}" | |
vars: | |
new_item: { 'cmd_check': 'fail' } | |
with_dict: "{{ fact_process }}" | |
- name: print variables again | |
debug: | |
var: fact_process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result: