--- - name: Dokku migration playbook hosts: localhost gather_facts: 'no' vars_files: - config.yml tasks: - name: Create temporary directory for SSH keypair tempfile: state: directory suffix: dokku_sync register: temp_dir - name: Generate SSH keypair community.crypto.openssh_keypair: path: "{{ temp_dir.path }}/dokku_sync_migration" type: ed25519 owner: "{{ lookup('env', 'USER') }}" group: "{{ lookup('env', 'USER') }}" mode: '0600' - name: Handle Source Server hosts: source gather_facts: 'yes' vars_files: - config.yml tasks: - name: Stop all Dokku apps command: dokku ps:stop --all - name: Stop all MariaDB services shell: dokku mariadb:list | tail -n+2 | xargs -iSERVICE dokku mariadb:stop SERVICE - name: Stop all PostgreSQL services shell: dokku postgres:list | tail -n+2 | xargs -iSERVICE dokku postgres:stop SERVICE - name: Stop all Redis services shell: dokku redis:list | tail -n+2 | xargs -iSERVICE dokku redis:stop SERVICE - name: Stop all MongoDB services shell: dokku mongo:list | tail -n+2 | xargs -iSERVICE dokku mongo:stop SERVICE - name: Stop Docker service service: name: docker state: stopped - name: Stop Docker socket service service: name: docker.socket state: stopped - name: Handle Destination Server hosts: destination gather_facts: yes vars_files: - config.yml tasks: - name: Stop all Dokku apps command: dokku ps:stop --all - name: Stop Docker service service: name: docker state: stopped - name: Stop Docker socket service service: name: docker.socket state: stopped - name: Create necessary directories file: path: "{{ item }}" state: directory owner: dokku group: dokku mode: '0755' loop: - /home/dokku/ - /home/data/ - /var/lib/dokku/ - name: Synchronize /home/dokku synchronize: src: "{{ source_host }}:/home/dokku/" dest: /home/dokku/ archive: 'yes' delete: 'yes' - name: Synchronize /var/lib/dokku synchronize: src: "{{ source_host }}:/var/lib/dokku/" dest: /var/lib/dokku/ archive: 'yes' delete: 'yes' - name: Synchronize /home/data synchronize: src: "{{ source_host }}:/home/data/" dest: /home/data/ archive: 'yes' delete: 'yes' - name: Synchronize /home/git synchronize: src: "{{ source_host }}:/home/git/" dest: /home/git/ archive: 'yes' delete: 'yes' - name: List Dokku apps command: dokku apps:list - name: Patch URLs in Dokku configuration files find: paths: - /home/dokku/ patterns: ['VHOST', 'URLS'] recurse: 'yes' register: dokku_config_files - name: Replace source host with destination host in configuration files lineinfile: path: "{{ item.path }}" regexp: "{{ source_host }}" line: "{{ destination_host }}" loop: "{{ dokku_config_files.files }}" - name: Display success message debug: msg: "SUCCESS"