Akron | a676c08 | 2024-03-25 20:03:05 +0100 | [diff] [blame^] | 1 | # Call as |
| 2 | # $ ansible-playbook -l test deploy-kalamar-plugin-externalresources.yml |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 3 | - name: Deploy Kalamar-Plugin-ExternalResources |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 4 | hosts: |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 5 | - test |
| 6 | - main |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 7 | serial: 1 |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 8 | run_once: true |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 9 | tasks: |
| 10 | - name: Save docker image |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 11 | local_action: ansible.builtin.command docker save {{ external_image }} -o ./kalamar-plugin-externalresources-latest.tar |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 12 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 13 | - name: Copy docker image to hosts |
| 14 | ansible.builtin.copy: |
| 15 | src: ./kalamar-plugin-externalresources-latest.tar |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 16 | dest: "{{ external_path }}/kalamar-plugin-externalresources-latest.tar" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 17 | mode: '0644' |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 18 | |
| 19 | - name: Delete docker image tar |
| 20 | local_action: |
| 21 | module: ansible.builtin.file |
| 22 | path: ./kalamar-plugin-externalresources-latest.tar |
| 23 | state: absent |
| 24 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 25 | - name: Load docker image on host |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 26 | ansible.builtin.command: "docker load -i {{ external_path }}/kalamar-plugin-externalresources-latest.tar" |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 27 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 28 | - name: Get UID for KorAP user |
| 29 | getent: |
| 30 | database: passwd |
| 31 | key: korap |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 32 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 33 | - name: Gracefully stop and remove old docker container, if existing |
| 34 | community.docker.docker_container: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 35 | image: "{{ external_image }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 36 | state: "absent" |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 37 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 38 | recreate: true |
| 39 | keep_volumes: true |
| 40 | comparisons: |
| 41 | image: ignore # do not restart containers with older versions of the image |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 42 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 43 | - name: Restart docker container |
| 44 | community.docker.docker_container: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 45 | image: "{{ external_image }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 46 | restart_policy: "unless-stopped" |
| 47 | pull: false |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 48 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 49 | user: "{{ ansible_facts.getent_passwd[\"korap\"].1 }}" |
| 50 | init: true |
| 51 | detach: true |
| 52 | mounts: |
| 53 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 54 | source: "{{ external_path }}/db" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 55 | target: "/db" |
| 56 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 57 | source: "{{ external_path }}/.env" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 58 | target: "/.env" |
| 59 | ports: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 60 | - "{{ external_port }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 61 | comparisons: |
| 62 | image: ignore # do not restart containers with older versions of the image |