'Update facts module ansible
I have created a dict with set_fact. Now I want to update only the value "dnu" with the update_fact module.
"PortRCR": [
{
"desc": null,
"dnu": "0",
"lp": "down",
"name": "GigabitEthernet0/0",
"os": "down"
},
{
"desc": "Router",
"dnu": "0",
"lp": "down",
"name": "GigabitEthernet1/0/1",
"os": "up"
},
{
"desc": null,
"dnu": "0",
"lp": "down",
"name": "GigabitEthernet1/0/10",
"os": "down"
My playbook looks like that:
set_fact:
PortRCR: "{{ PortRCR + [{'name': item.key, 'desc': item.value.description, 'lp': item.value.lineprotocol | default('down', true), 'os': item.value.operstatus, 'dnu': '' | default('0', true) }] }}"
PortRCR_length: "{{ PortRCR | length }}"
cacheable: yes
loop: "{{ ansible_net_interfaces | dict2items }}"
vars:
PortRCR: []
- name: Update the fact
ansible.utils.update_fact:
updates:
- path: PortRCR{{ item }}['dnu']
value: "1"
loop: "{{ range(0, PortRCR_length|int)|list }}"
Ansible tells me the fact was changed but the value is untouched.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
