From 4e6c7a6b0efa4a8b291faafdbab9a9c6b0ce23e2 Mon Sep 17 00:00:00 2001 From: enricostano Date: Mon, 26 Jun 2023 00:04:37 +0200 Subject: [PATCH 1/4] Install odoo package if not installed in virtualenv --- tasks/main.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index b3d9960..062ec46 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -119,11 +119,19 @@ state: link when: odoo_role_odoo_version < "12.0" and ansible_distribution == "Ubuntu" and not ansible_distribution_version >= "18.04" +- name: Check if Odoo is already installed in virtualenv + become: true + become_user: "{{ odoo_role_odoo_user }}" + ansible.builtin.shell: > + {{ odoo_role_odoo_python_path }} -m pip list | grep odoo + register: odoo_package_is_installed + failed_when: odoo_package_is_installed.rc not in [0,1] + - name: Install Odoo become: true become_user: "{{ odoo_role_odoo_user }}" shell: "cd {{ odoo_role_odoo_path }} && {{ odoo_role_odoo_python_path }} setup.py install" - when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed + when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.stdout == '' - name: Populate community db modules set_fact: From ee6af03bd558dfa7cb9658c63743a7a632acb9bd Mon Sep 17 00:00:00 2001 From: enricostano Date: Mon, 26 Jun 2023 00:04:22 +0200 Subject: [PATCH 2/4] Create python packages requirements.txt file from template --- README.md | 44 ++++++++++++++++++++++++----------- tasks/community-modules.yml | 10 +++++--- tasks/main.yml | 4 ++-- templates/requirements.txt.j2 | 9 +++++++ 4 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 templates/requirements.txt.j2 diff --git a/README.md b/README.md index 610ad1e..0a0e39b 100644 --- a/README.md +++ b/README.md @@ -227,28 +227,46 @@ This tag helps you install or update Odoo modules without performing a full setu ansible-playbook playbook.yml --tags "only-modules" ``` -Community Roles ---------------- +Odoo modules +------------ #### Deploy -To use community roles, you need to deploy this modules in the server. This role manage the modules deployment with `pip`. +To use Odoo modules (from OCA or custom modules), you need to deploy modules packages to the server. This role manages the modules deployment with `pip`. +In your inventory you can define up to two variables in order to add python packages to the target `requirements.txt` that will be generated. -You can define a `requirements.txt` file to manage the modules and ensure the version installed: +Define the `odoo_role_odoo_community_packages` variable to install packages not maintained by you. For example when you're deploying an Odoo instance that just requires OCA modules: +```yml +# inventory/group_vars/all.yml +odoo_role_odoo_community_packages: + - odoo11-addon-contract==11.0.2.1.0 + - odoo11-addon-contract-sale-invoicing==11.0.1.0.0 + - odoo11-addon-contract-variable-qty-timesheet==11.0.1.0.0 + - odoo11-addon-contract-variable-quantity==11.0.1.2.1 ``` -# requirements.txt -odoo11-addon-contract==11.0.2.1.0 -odoo11-addon-contract-sale-invoicing==11.0.1.0.0 -odoo11-addon-contract-variable-qty-timesheet==11.0.1.0.0 -odoo11-addon-contract-variable-quantity==11.0.1.2.1 + +In some case you want to deploy different versions of the same module to different hosts. +A typical case is when you have developed a custom module and need to deploy a packaged version of it to production but in local development environment you need to install it es editable. +In this case you can define the `odoo_role_odoo_project_packages` variable: +```yml +# inventory/host_vars/production.yml +odoo_role_odoo_project_packages: + - odoo14-my-custom-module==14.0.0.1.0 +``` + +```yml +# inventory/host_vars/development.yml +odoo_role_odoo_project_packages: + - '-e file:///opt/odoo_modules/setup/my_custom_module' ``` -> The default the `requirements.txt` file path is `"{{ inventory_dir }}/../files/requirements.txt"`. +For backward compatibility, the Ansible template will look first for a `files/requirements.txt` file in your inventory and use it as the source of the template. +If you have a `files/requirements.txt` file defined in your inventory, the two variables just described will not take any effect. -# Install -Once the modules are in the server, you need to install them in the database. +#### Install +Once the modules packages are installed in the server, you need to install them in the Odoo database. -Define a `odoo_role_odoo_community_modules` var with the list of the modules names you want to install. +Define a `odoo_role_odoo_community_modules` variable with the list of the modules names you want to install. ```yml # inventory/group_vars/all.yml diff --git a/tasks/community-modules.yml b/tasks/community-modules.yml index 7305f41..a436921 100644 --- a/tasks/community-modules.yml +++ b/tasks/community-modules.yml @@ -1,11 +1,15 @@ --- -- name: Copy requirements.txt - copy: - src: "{{ odoo_role_community_modules_requirements_path }}" +- name: Create requirements.txt from template + ansible.builtin.template: + src: "{{ lookup('ansible.builtin.first_found', template_sources) }}" dest: "{{ odoo_role_odoo_modules_path }}/requirements.txt" owner: "{{ odoo_role_odoo_user }}" group: "{{ odoo_role_odoo_group }}" mode: 0644 + vars: + template_sources: + - "{{ inventory_dir }}/../files/requirements.txt" + - templates/requirements.txt.j2 tags: ['community-modules', 'only-modules'] - name: Deploy community roles with pip diff --git a/tasks/main.yml b/tasks/main.yml index 062ec46..049f449 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -123,7 +123,7 @@ become: true become_user: "{{ odoo_role_odoo_user }}" ansible.builtin.shell: > - {{ odoo_role_odoo_python_path }} -m pip list | grep odoo + {{ odoo_role_odoo_python_path }} -m pip show odoo register: odoo_package_is_installed failed_when: odoo_package_is_installed.rc not in [0,1] @@ -131,7 +131,7 @@ become: true become_user: "{{ odoo_role_odoo_user }}" shell: "cd {{ odoo_role_odoo_path }} && {{ odoo_role_odoo_python_path }} setup.py install" - when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.stdout == '' + when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.rc == 1 - name: Populate community db modules set_fact: diff --git a/templates/requirements.txt.j2 b/templates/requirements.txt.j2 new file mode 100644 index 0000000..712be96 --- /dev/null +++ b/templates/requirements.txt.j2 @@ -0,0 +1,9 @@ +# {{ ansible_managed }} + +{% for package in odoo_role_odoo_community_packages|default([]) %} +{{ package }} +{% endfor %} + +{% for package in odoo_role_odoo_project_packages|default([]) %} +{{ package }} +{% endfor %} From bd05cfccd11329387901f49279b500cab6021e44 Mon Sep 17 00:00:00 2001 From: Enrico Stano Date: Tue, 18 Jul 2023 09:16:16 +0200 Subject: [PATCH 3/4] Define more explicit conditions to install Odoo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Pelayo García <25091358+oyale@users.noreply.github.com> --- tasks/main.yml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 049f449..75652cf 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -119,13 +119,26 @@ state: link when: odoo_role_odoo_version < "12.0" and ansible_distribution == "Ubuntu" and not ansible_distribution_version >= "18.04" + - name: Check if Odoo is already installed in virtualenv become: true become_user: "{{ odoo_role_odoo_user }}" ansible.builtin.shell: > {{ odoo_role_odoo_python_path }} -m pip show odoo - register: odoo_package_is_installed + register: odoo_package_check failed_when: odoo_package_is_installed.rc not in [0,1] + +- name: Set boolean for Odoo package installation + set_fact: + odoo_package_not_installed: "{{ odoo_package_check.rc == 1 }}" + +- name: Determine if Odoo needs to be installed or reinstalled + set_fact: + odoo_install_required: >- + (odoo_role_desired_tar_download.changed) or + (odoo_role_desired_git_download.changed) or + (odoo_package_not_installed) or + (odoo_role_force_install | default(false)) - name: Install Odoo become: true From 67f5d846415fb6b01a5afcef259f391ca389a0d1 Mon Sep 17 00:00:00 2001 From: Enrico Stano Date: Tue, 18 Jul 2023 09:16:40 +0200 Subject: [PATCH 4/4] Use more explicit conditions to install Odoo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Pelayo García <25091358+oyale@users.noreply.github.com> --- tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/main.yml b/tasks/main.yml index 75652cf..391a891 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -144,7 +144,7 @@ become: true become_user: "{{ odoo_role_odoo_user }}" shell: "cd {{ odoo_role_odoo_path }} && {{ odoo_role_odoo_python_path }} setup.py install" - when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.rc == 1 + when: odoo_install_required - name: Populate community db modules set_fact: