diff --git a/ansible/plays/docker.yaml b/ansible/plays/docker.yaml new file mode 100644 index 0000000..a5581a2 --- /dev/null +++ b/ansible/plays/docker.yaml @@ -0,0 +1,41 @@ +- name: Migrate to docker compose v2 + hosts: all + become: true + become_user: root + pre_tasks: + - name: Find deployed projects + ansible.builtin.find: + paths: /home/core/compose + recurse: no + file_type: directory + register: find_challenges + - name: Register Projects Fact + ansible.builtin.set_fact: + deployed_challenges: "{{ find_challenges.files | map(attribute='path') | map('basename') }}" + - name: Undeploy + include_tasks: undeploy.yaml + loop: "{{ deployed_challenges | mandatory }}" + loop_control: + loop_var: item + label: "{{ item }}" + tasks: + - name: Install Repo + copy: + dest: /etc/yum.repos.d/docker-ce.repo + src: docker.repo + owner: root + group: root + mode: '0644' + - name: Remove legacy versions + command: "rpm-ostree override remove --reboot docker containerd runc" + async: true + poll: 0 + ignore_errors: true + - name: Wait for host + ansible.builtin.wait_for_connection: + delay: 90 + - name: Install new docker versions + command: "rpm-ostree install -A -y --idempotent docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-buildx-plugin" + +- name: Redeploy + ansible.builtin.import_playbook: ../playbook.yaml diff --git a/ansible/plays/files/docker.repo b/ansible/plays/files/docker.repo new file mode 100644 index 0000000..8a0de16 --- /dev/null +++ b/ansible/plays/files/docker.repo @@ -0,0 +1,6 @@ +[docker-ce-stable] +name=Docker CE Stable - $basearch +baseurl=https://download.docker.com/linux/fedora/$releasever/$basearch/stable +enabled=1 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/fedora/gpg diff --git a/ansible/plays/undeploy.yaml b/ansible/plays/undeploy.yaml new file mode 100644 index 0000000..17e0e1d --- /dev/null +++ b/ansible/plays/undeploy.yaml @@ -0,0 +1,20 @@ +- name: Undeploy service + block: + - name: Set service_dir + ansible.builtin.set_fact: + service_dir: "/home/core/compose/{{ item | mandatory }}" + - name: Check if service is present + stat: + path: "{{ service_dir | mandatory }}" + register: dir + - name: Stop Service + community.docker.docker_compose: + project_src: "{{ service_dir | mandatory }}" + state: absent + remove_orphans: true + when: dir.stat.exists == True + - name: Remove Service + file: + state: absent + path: "{{ service_dir | mandatory }}" + when: dir.stat.exists == True