blob: 44b59bd3df064f2ee7751fd96c582f3e9b263ec2 [file] [log] [blame]
Akrona676c082024-03-25 20:03:05 +01001# Call as
2# $ ansible-playbook -l test deploy-kalamar-plugin-externalresources.yml
Akrone53ef3a2024-03-19 11:27:11 +01003- name: Deploy Kalamar-Plugin-ExternalResources
Akrona79b6ff2024-03-15 12:32:44 +01004 hosts:
Akron6c26c6a2024-03-19 14:19:53 +01005 - test
6 - main
Akrona79b6ff2024-03-15 12:32:44 +01007 serial: 1
Akron6c26c6a2024-03-19 14:19:53 +01008 run_once: true
Akrona79b6ff2024-03-15 12:32:44 +01009 tasks:
10 - name: Save docker image
Akron700679f2024-03-19 16:41:36 +010011 local_action: ansible.builtin.command docker save {{ external_image }} -o ./kalamar-plugin-externalresources-latest.tar
Akrone53ef3a2024-03-19 11:27:11 +010012
Akrona79b6ff2024-03-15 12:32:44 +010013 - name: Copy docker image to hosts
14 ansible.builtin.copy:
15 src: ./kalamar-plugin-externalresources-latest.tar
Akron6c26c6a2024-03-19 14:19:53 +010016 dest: "{{ external_path }}/kalamar-plugin-externalresources-latest.tar"
Akrona79b6ff2024-03-15 12:32:44 +010017 mode: '0644'
Akrone53ef3a2024-03-19 11:27:11 +010018
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
Akrona79b6ff2024-03-15 12:32:44 +010025 - name: Load docker image on host
Akron6c26c6a2024-03-19 14:19:53 +010026 ansible.builtin.command: "docker load -i {{ external_path }}/kalamar-plugin-externalresources-latest.tar"
Akrone53ef3a2024-03-19 11:27:11 +010027
Akrona79b6ff2024-03-15 12:32:44 +010028 - name: Get UID for KorAP user
29 getent:
30 database: passwd
31 key: korap
Akrone53ef3a2024-03-19 11:27:11 +010032
Akrona79b6ff2024-03-15 12:32:44 +010033 - name: Gracefully stop and remove old docker container, if existing
34 community.docker.docker_container:
Akron700679f2024-03-19 16:41:36 +010035 image: "{{ external_image }}"
Akrona79b6ff2024-03-15 12:32:44 +010036 state: "absent"
Akron6c26c6a2024-03-19 14:19:53 +010037 name: "{{ external_container_name }}"
Akrona79b6ff2024-03-15 12:32:44 +010038 recreate: true
39 keep_volumes: true
40 comparisons:
41 image: ignore # do not restart containers with older versions of the image
Akrone53ef3a2024-03-19 11:27:11 +010042
Akrona79b6ff2024-03-15 12:32:44 +010043 - name: Restart docker container
44 community.docker.docker_container:
Akron700679f2024-03-19 16:41:36 +010045 image: "{{ external_image }}"
Akrona79b6ff2024-03-15 12:32:44 +010046 restart_policy: "unless-stopped"
47 pull: false
Akron6c26c6a2024-03-19 14:19:53 +010048 name: "{{ external_container_name }}"
Akrona79b6ff2024-03-15 12:32:44 +010049 user: "{{ ansible_facts.getent_passwd[\"korap\"].1 }}"
50 init: true
51 detach: true
52 mounts:
53 - type: bind
Akron6c26c6a2024-03-19 14:19:53 +010054 source: "{{ external_path }}/db"
Akrona79b6ff2024-03-15 12:32:44 +010055 target: "/db"
56 - type: bind
Akron6c26c6a2024-03-19 14:19:53 +010057 source: "{{ external_path }}/.env"
Akrona79b6ff2024-03-15 12:32:44 +010058 target: "/.env"
59 ports:
Akron700679f2024-03-19 16:41:36 +010060 - "{{ external_port }}"
Akrona79b6ff2024-03-15 12:32:44 +010061 comparisons:
62 image: ignore # do not restart containers with older versions of the image