Advertisement
gregmark

Remove dict item in two tasks

Jun 6th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.89 KB | None | 0 0
  1. ---
  2. - hosts: localhost
  3.   connection: local
  4.   gather_facts: false
  5.   tasks:
  6.   - name: "Set the test facts"
  7.     set_fact:
  8.       new_inner_dict:
  9.         foo: "bar"
  10.       full_dict:
  11.         outer_key: "outer key value"
  12.         outer_dict:
  13.           inner_key: "inner key value"
  14.           inner_dict:
  15.             foo: "bar"
  16.             remove: "me"
  17.   - name: "This is the full dictionary"
  18.     debug:
  19.       var: full_dict
  20.   - name: erase inner_dict
  21.     set_fact:
  22.       full_dict: "{{ full_dict | combine({'outer_dict': {'inner_dict': None }}, recursive=True) }}"
  23.   - name: "Use 'combine' to set inner_dict to a dictionary that does not have 'remove: me' item"
  24.     set_fact:
  25.       full_dict: "{{ full_dict | combine({'outer_dict': {'inner_dict': new_inner_dict }}, recursive=True) }}"
  26.   - name: "Now notice the 'remove: me' item is gone from the inner_dict"
  27.     debug:
  28.       var: full_dict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement