diff --git a/ansible/requirements.yml b/ansible/requirements.yml index 3f10678b..fc4d4830 100644 --- a/ansible/requirements.yml +++ b/ansible/requirements.yml @@ -3,6 +3,6 @@ collections: - name: ansible.posix version: 1.5.4 - name: community.docker - version: 3.4.11 + version: 3.6.0 - name: community.general - version: 8.0.2 + version: 8.2.0 diff --git a/ansible/roles/ovos_installer/tasks/docker/common.yml b/ansible/roles/ovos_installer/tasks/docker/common.yml index 18095f43..6acfecb0 100644 --- a/ansible/roles/ovos_installer/tasks/docker/common.yml +++ b/ansible/roles/ovos_installer/tasks/docker/common.yml @@ -17,15 +17,6 @@ enabled: true state: started -- name: Install Python docker and docker-compose libraries - ansible.builtin.pip: - name: - - docker==6.1.3 - - docker-compose - virtualenv: "{{ ovos_installer_venv }}" - tags: - - always - - name: Clone ovos-docker and/or hivemind-docker repository ansible.builtin.git: repo: "{{ item.url }}" @@ -33,8 +24,18 @@ version: "{{ item.branch }}" force: true loop: - - {"url": "{{ ovos_installer_ovos_docker_repo_url }}", "branch": "{{ ovos_installer_ovos_docker_repo_branch }}", "dest": "ovos-docker", "state": "{{ true if (ovos_installer_profile != 'satellite' or ovos_installer_cleaning | bool) else false }}"} - - {"url": "{{ ovos_installer_hivemind_docker_repo_url }}", "branch": "{{ ovos_installer_hivemind_docker_repo_branch }}", "dest": "hivemind-docker", "state": "{{ true if (ovos_installer_profile == 'satellite' or ovos_installer_cleaning | bool) else false }}"} + - { + "url": "{{ ovos_installer_ovos_docker_repo_url }}", + "branch": "{{ ovos_installer_ovos_docker_repo_branch }}", + "dest": "ovos-docker", + "state": "{{ true if (ovos_installer_profile != 'satellite' or ovos_installer_cleaning | bool) else false }}", + } + - { + "url": "{{ ovos_installer_hivemind_docker_repo_url }}", + "branch": "{{ ovos_installer_hivemind_docker_repo_branch }}", + "dest": "hivemind-docker", + "state": "{{ true if (ovos_installer_profile == 'satellite' or ovos_installer_cleaning | bool) else false }}", + } when: item.state | bool tags: - always diff --git a/ansible/roles/ovos_installer/tasks/docker/composer.yml b/ansible/roles/ovos_installer/tasks/docker/composer.yml index 55efa67e..ba247636 100644 --- a/ansible/roles/ovos_installer/tasks/docker/composer.yml +++ b/ansible/roles/ovos_installer/tasks/docker/composer.yml @@ -12,42 +12,30 @@ register: _ovos_installer_timezone changed_when: false +- name: Set _composition_directory fact + ansible.builtin.set_fact: + _composition_directory: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose" + tags: + - always + - name: Generate .env file for docker-compose ansible.builtin.template: src: docker/env.j2 - dest: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose/.env" + dest: "{{ _composition_directory }}/.env" owner: root group: root - mode: '0644' + mode: "0644" tags: - always -# Required because docker-compose (not docker compose) doesn't support userns option -- name: Remove YAML x-podman function from composition files - vars: - _remove_x_podman_ovos: "{{ 'true' if ovos_installer_profile != 'satellite' else 'false' }}" - _remove_x_podman_satellite: "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}" - ansible.builtin.lineinfile: - path: "{{ item.file }}" - search_string: "<<: *podman" - state: absent - loop: - - {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.yml", "state": "{{ _remove_x_podman_ovos }}"} - - {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.skills.yml", "state": "{{ _remove_x_podman_ovos }}"} - - {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.hivemind.yml", "state": "{{ _remove_x_podman_ovos }}"} - - {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.gui.yml", "state": "{{ _remove_x_podman_ovos }}"} - - {"file": "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.windows.yml", "state": "{{ _remove_x_podman_ovos }}"} - - {"file": "{{ _ovos_installer_working_directory }}/hivemind-docker/compose/docker-compose.satellite.yml", "state": "{{ _remove_x_podman_satellite }}"} - when: item.state | bool - - name: Remove DISPLAY variable if EGLFS is used ansible.builtin.lineinfile: - path: "{{ _ovos_installer_working_directory }}/ovos-docker/compose/docker-compose.gui.yml" + path: "{{ _composition_directory }}/docker-compose.gui.yml" search_string: "DISPLAY" state: absent when: ovos_installer_profile != 'satellite' and - ovos_installer_feature_gui | bool and - ovos_installer_display_server == 'N/A' + ovos_installer_feature_gui | bool and + ovos_installer_display_server == 'N/A' - name: Define composition vars: @@ -55,26 +43,54 @@ ansible.builtin.set_fact: _composition_files: "{{ _composition_files | default([]) + [item.file] }}" loop: - - {"file": "docker-compose.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'linux') else 'false' }}"} - - {"file": "docker-compose.windows.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'wsl2') else 'false' }}"} - - {"file": "docker-compose.raspberrypi.yml", "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A') else 'false' }}"} - - {"file": "docker-compose.skills.yml", "state": "{{ 'false' if (ansible_memtotal_mb < 2048 and ovos_installer_profile != 'satellite' or not ovos_installer_feature_skills | bool) else 'true' }}"} - - {"file": "docker-compose.hivemind.yml", "state": "{{ 'true' if ovos_installer_profile == 'listener' else 'false' }}"} - - {"file": "docker-compose.gui.yml", "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_feature_gui | bool) else 'false' }}"} - - {"file": "docker-compose.raspberrypi.gui.yml", "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A' and ovos_installer_feature_gui | bool) else 'false' }}"} - - {"file": "docker-compose.satellite.yml", "state": "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}"} + - { + "file": "docker-compose.yml", + "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'linux') else 'false' }}", + } + - { + "file": "docker-compose.windows.yml", + "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and _os_type == 'wsl2') else 'false' }}", + } + - { + "file": "docker-compose.raspberrypi.yml", + "state": "{{ 'true' if (ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A') else 'false' }}", + } + - { + "file": "docker-compose.skills.yml", + "state": "{{ 'false' if (ansible_memtotal_mb < 2048 and ovos_installer_profile != 'satellite' or not ovos_installer_feature_skills | bool) else 'true' }}", + } + - { + "file": "docker-compose.hivemind.yml", + "state": "{{ 'true' if ovos_installer_profile == 'listener' else 'false' }}", + } + - { + "file": "docker-compose.gui.yml", + "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_feature_gui | bool) else 'false' }}", + } + - { + "file": "docker-compose.raspberrypi.gui.yml", + "state": "{{ 'true' if (ansible_memtotal_mb >= 2048 and ovos_installer_profile != 'satellite' and ovos_installer_raspberrypi != 'N/A' and ovos_installer_feature_gui | bool) else 'false' }}", + } + - { + "file": "docker-compose.satellite.yml", + "state": "{{ 'true' if ovos_installer_profile == 'satellite' else 'false' }}", + } when: item.state | bool +- name: Merge composition files into compose.yaml + ansible.builtin.template: + src: docker/compose.yaml.j2 + dest: "{{ _composition_directory }}/compose.yaml" + - name: Deploy docker-compose stack become: true become_user: "{{ ovos_installer_user }}" vars: _project_name: "{{ 'hivemind' if ovos_installer_profile == 'satellite' else 'ovos' }}" - community.docker.docker_compose: - project_src: "{{ _ovos_installer_working_directory }}/{{ _ovos_installer_project_name }}/compose" + community.docker.docker_compose_v2: + project_src: "{{ _composition_directory }}" project_name: "{{ _project_name }}" - files: "{{ _composition_files }}" - pull: true + pull: always remove_orphans: "{{ ovos_installer_docker_compose_remove_orphans }}" remove_images: "{{ ovos_installer_docker_compose_remove_images }}" remove_volumes: "{{ ovos_installer_docker_compose_remove_volumes }}" @@ -95,18 +111,49 @@ become_user: "{{ ovos_installer_user }}" vars: _composition_mapping: - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.raspberrypi.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.skills.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.hivemind.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.gui.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.raspberrypi.gui.yml"} - - {"src": "ovos-docker", "name": "ovos", "file": "docker-compose.windows.yml"} - - {"src": "hivemind-docker", "name": "hivemind", "file": "docker-compose.satellite.yml"} - community.docker.docker_compose: - project_src: "{{ _ovos_installer_working_directory }}/{{ item.src }}/compose" + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.raspberrypi.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.skills.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.hivemind.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.gui.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.raspberrypi.gui.yml", + } + - { + "src": "ovos-docker", + "name": "ovos", + "file": "docker-compose.windows.yml", + } + - { + "src": "hivemind-docker", + "name": "hivemind", + "file": "docker-compose.satellite.yml", + } + community.docker.docker_compose_v2: + project_src: "{{ _composition_directory }}" project_name: "{{ item.name }}" - files: "{{ item.file }}" remove_orphans: "{{ ovos_installer_docker_compose_remove_orphans }}" remove_images: "{{ ovos_installer_docker_compose_remove_images }}" remove_volumes: "{{ ovos_installer_docker_compose_remove_volumes }}" @@ -116,7 +163,7 @@ environment: DOCKER_TIMEOUT: "900" register: _composer_deletion - failed_when: _composer_deletion is not defined # We never want it to fail even if systemd unit doesn't exist + failed_when: _composer_deletion is not defined # We never want it to fail - name: Remove directories ansible.builtin.file: @@ -133,3 +180,5 @@ loop: - "{{ _ovos_installer_working_directory }}/ovos-docker" - "{{ _ovos_installer_working_directory }}/hivemind-docker" + tags: + - always diff --git a/ansible/roles/ovos_installer/templates/docker/compose.yaml.j2 b/ansible/roles/ovos_installer/templates/docker/compose.yaml.j2 new file mode 100644 index 00000000..09389b49 --- /dev/null +++ b/ansible/roles/ovos_installer/templates/docker/compose.yaml.j2 @@ -0,0 +1,3 @@ +{% for _composition_file in _composition_files %} +{{ lookup('file', _composition_directory + '/' + _composition_file) }} +{% endfor %} diff --git a/utils/common.sh b/utils/common.sh index ddbe3be0..00a1a38d 100644 --- a/utils/common.sh +++ b/utils/common.sh @@ -242,12 +242,9 @@ function create_python_venv() { # Install Ansible into the new Python virtual environment and install the # Ansible collections required by the Ansible playbook as well. These # collection will be installed under the /root/.ansible directory. -# -# NOTE: PyYAML is downgraded because of docker-compose Python library which -# does not support PyYAML > 5.3.1 version. function install_ansible() { echo -ne "➤ Installing Ansible requirements in Python virtualenv... " - pip3 install ansible==8.6.1 PyYAML==5.3.1 &>>"$LOG_FILE" + pip3 install ansible==9.1.0 docker==7.0.0 &>>"$LOG_FILE" ansible-galaxy collection install -r ansible/requirements.yml &>>"$LOG_FILE" echo -e "[$done_format]" }