Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bodsch/3ac00cc6d4d4cc9e309076795412e36f to your computer and use it in GitHub Desktop.
Save bodsch/3ac00cc6d4d4cc9e309076795412e36f to your computer and use it in GitHub Desktop.

Revisions

  1. @hatsari hatsari revised this gist Oct 31, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions ansible_replace_the_value_of_dic_variable.yaml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    ---
    ### 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
  2. @hatsari hatsari created this gist Oct 31, 2018.
    24 changes: 24 additions & 0 deletions ansible_replace_the_value_of_dic_variable.yaml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    ---
    - 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