canonical / maas-ansible-playbook

An Ansible playbook for installing and configuring MAAS
Apache License 2.0
44 stars 34 forks source link

Restoring config fails #52

Open ben-ihelputech opened 1 year ago

ben-ihelputech commented 1 year ago
$ ansible-playbook -i ./hosts --extra-vars="maas_installation_type=snap maas_backup_file=/backups/postgres/localhost_maas_backup_2022-12-02T22:10:29Z.tgz" ./restore.yaml -K 
BECOME password: 

PLAY [maas_postgres_primary,maas_region_controller,maas_rack_controller] *************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Restore from backup] ***********************************************************************************************************************************************************************************************************************************

TASK [common : Create Temporary Unpack Directory] ************************************************************************************************************************************************************************************************************
changed: [localhost]

TASK [common : Unpack Backup Archive] ************************************************************************************************************************************************************************************************************************
changed: [localhost]

TASK [common : Stop Region Controller] ***********************************************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [common : Stop Rack Controller] *************************************************************************************************************************************************************************************************************************
skipping: [localhost]

TASK [common : Stop MAAS snap] *******************************************************************************************************************************************************************************************************************************
changed: [localhost]

TASK [common : Restore Config] *******************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": true, "cmd": ["mv", "/tmp/maas_backup/etc/maas"], "delta": "0:00:00.006119", "end": "2022-12-02 16:28:49.906386", "msg": "non-zero return code", "rc": 1, "start": "2022-12-02 16:28:49.900267", "stderr": "mv: missing destination file operand after '/tmp/maas_backup/etc/maas'\nTry 'mv --help' for more information.", "stderr_lines": ["mv: missing destination file operand after '/tmp/maas_backup/etc/maas'", "Try 'mv --help' for more information."], "stdout": "", "stdout_lines": []}

PLAY RECAP ***************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=4    changed=3    unreachable=0    failed=1    skipped=2    rescued=0    ignored=0   
ben-ihelputech commented 1 year ago

So I did some more digging and I created a test playbook using just the code that is currently in use by the playbook. I hard coded the variables for my environment and ran the playbook:

---
- hosts:
    - maas_postgres_primary
  tasks:
    - name: Create Temporary Unpack Directory
      ansible.builtin.file:
        path: /tmp/maas_backup/
        owner: root
        group: root
        mode: '0755'
        state: directory
    - name: Unarchive file
      ansible.builtin.unarchive:
        src: /backups/postgres/pickme.tgz
        dest: /tmp/maas_backup
  become: yes
  gather_facts: true

What I noticed when it was done is that it returned a gz file in the dest directory:

$ ls /tmp/maas_backup/
dump.sql.gz

So it seems to me that the reason the playbook fails is that ansible is not fully unarchiving the .tgz file and then expects there to be data in the {backup-dir}/etc/maas section.