Ansible - Updated hash value

Let's say you've defined two key value pairs using the vars plugin.

- hosts: all
      - { key: 'fruit', value: 'apple' }
      - { key: 'veggy', value: 'onion' }


The debug module can be used to output the hash.

- name: "output the contents of the 'food' hash"
    var: food


Which should return the following.

TASK [output the contents of the 'food' hash]
ok: [] => {
    "food": [
            "key": "fruit",
            "value": "apple"
            "key": "veggy",
            "value": "onion"


Let's say you want to update apple to banana. The simplest way to get this done is to redefine the hash value using the set_fact module.

- set_fact:
      - { key: 'fruit', value: 'banana' }



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter b44f4 in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |