FreeKB - Ansible Updated hash value
Ansible - Updated hash value

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

---
- hosts: all
  vars:
    food: 
      - { 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"
  debug: 
    var: food

 

Which should return the following.

TASK [output the contents of the 'food' hash]
ok: [server1.example.com] => {
    "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:
    food: 
      - { 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 6f190 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |