Hi,
I would like to append to a list of dictionaries between the playbook executions for all hosts. However it seems that the list does not retain the appended items.
I am using ansible [core 2.13.13].
Here is my playbook:
- name: “Test”
hosts: all_router
gather_facts: no
vars:
backup_status:
tasks:- name: add items to list
set_fact:
backup_status: “{{ backup_status + [{‘hostname’: inventory_hostname, ‘status’: ‘Succeeded’}] }}”
cacheable: yes
delegate_to: localhost - name: debug
debug:
msg: “{{ backup_status }}”
- name: add items to list
Output:
TASK [debug] *********************************************************************************************************
ok: [172.x1.y1.z1] => {
“msg”: [
{
“hostname”: “172.x1.y1.z1”,
“status”: “Succeeded”
}
]
}
ok: [172.x2.y2.z2] => {
“msg”: [
{
“hostname”: “172.x2.y2.z2”,
“status”: “Succeeded”
}
]
}
ok: [172.x3.y3.z3] => {
“msg”: [
{
“hostname”: “172.x3.y3.z3”,
“status”: “Succeeded”
}
]
}
Here is my ansible.cfg file
[defaults]
inventory = inventory.ini
host_key_checking = False
interpreter_python=auto_silent
display_skipped_hosts = false
fact_caching = jsonfile
fact_caching_connection = cache
It looks like that it doesn’t retain the entries between different executions.
Thanks in advance for your help!