# Update extra-vars and save to disk.

**URL:** <https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506>\
**Category:** Get Help\
**Tags:** update\
**Created:** [October 21, 2026, 1:34pm UTC](https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506 "2026-10-21T13:34:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kh23776](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kh23776](https://forum.ansible.com/u/kh23776)\
**Post date:** [October 21, 2026, 1:34pm UTC](https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506/1 "2026-10-21T13:34:07Z")

</div>

Morning All

I run some backups from Ansible  
ansible-playbook backup.yml   
-i “$ANSIBLE\_PLAY/bin/servers.sh”   
–extra-vars “@database.yml”   
–extra-vars “db\_name=MyDatabase”

Works perfectly.  
Backs up the MyDatabase using the paramaters in database.yml  
But once the backup has completed, I’d like to update one the variabkes in database.yml to say te backup was successful.

I’m not even sure where to start looking - can someone point me in the right direction please…

* * *

## MyDatabase: Type: Database Env: PPE Services: Primary: myDB\_PRIMARY.LOCAL Standby: myDB\_STANDBY.LOCAL Type: TCPIP Backup: service: mydb\_bkp full\_backup\_day: SUN retention: 7 **LastBack: success** \<= this to update, DataCentres: Locations: [“DC3”, “DC4”] DC3: g\_db\_unique\_name: “mydb” g\_db\_sid: “mydb” DC4: g\_db\_unique\_name: “mydb” g\_db\_sid: “mydb”

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [October 21, 2026, 10:11pm UTC](https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506/2 "2026-10-21T22:11:27Z")

</div>

Updating a hardcoded extra variable from a playbook isn’t a typical pattern, there might be a better approach. Have you considered using a task in the playbook to check if the backup exists instead? The extra variable could be defined using Jinja2, and reference the registered task result and fall back to a default value.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [October 22, 2026, 1:57am UTC](https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506/3 "2026-10-22T01:57:06Z")

</div>

Given database.yml

```yaml
MyDatabase:
  Type: Database
  Env: PPE
Services:
  Primary: myDB_PRIMARY.LOCAL
  Standby: myDB_STANDBY.LOCAL
  Type: TCPIP
Backup:
  service: mydb_bkp
  full_backup_day: SUN
  retention: 7
  LastBack: success <= this to update,
DataCentres:
  Locations: [DC3, DC4]
DC3:
  g_db_unique_name: mydb
  g_db_sid: mydb
DC4:
  g_db_unique_name: mydb
  g_db_sid: mydb

```

The playbook pb.yml:

```yaml
- hosts: localhost

  tasks:

    - name: Backup.
      block:
        - debug:
            msg: "{{ db_name }}: Success."
      rescue:
        - debug:
            msg: "{{ db_name }}: Error."
        - meta: end_host

    - name: Record.
      block:
        - include_vars:
            file: database.yml
            name: database
        - template:
            src: database.yml.j2
            dest: database.yml
          vars:
            update:
              Backup:
                LastBack: "{{ '%Y-%m-%d %H:%M:%S' | strftime }}"
            _database: "{{ [database, update] | combine(recursive=true) }}"

```

Updates database.yml on success:

```sh
shell> ansible-playbook -e db_name=MyDatabase -e @database.yml pb.yml

```

```yaml

PLAY [localhost] ***************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => 
    msg: 'MyDatabase: Success.'

TASK [include_vars] ************************************************************
ok: [localhost]

TASK [template] ****************************************************************
changed: [localhost]

PLAY RECAP *********************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0   

```

templates/database.yml.j2

```yaml
{{ _database | to_nice_yaml }}

```

Updated database.yml

```yaml
Backup:
    LastBack: '2026-10-22 03:52:50'
    full_backup_day: SUN
    retention: 7
    service: mydb_bkp
DC3:
    g_db_sid: mydb
    g_db_unique_name: mydb
DC4:
    g_db_sid: mydb
    g_db_unique_name: mydb
DataCentres:
    Locations:
    - DC3
    - DC4
MyDatabase:
    Env: PPE
    Type: Database
Services:
    Primary: myDB_PRIMARY.LOCAL
    Standby: myDB_STANDBY.LOCAL
    Type: TCPIP

```

---

<div class="post-metadata">

**Author:** ![kh23776](https://avatars.discourse-cdn.com/v4/letter/k/7cd45c/32.png) [@kh23776](https://forum.ansible.com/u/kh23776)\
**Post date:** [October 22, 2026, 7:04am UTC](https://forum.ansible.com/t/update-extra-vars-and-save-to-disk/46506/4 "2026-10-22T07:04:12Z")

</div>

Awesome - thanks Vladimir. This worked perfectly for me.
