Skip to content

Commit ee6af03

Browse files
committed
Create python packages requirements.txt file from template
1 parent 4e6c7a6 commit ee6af03

File tree

4 files changed

+49
-18
lines changed

4 files changed

+49
-18
lines changed

README.md

+31-13
Original file line numberDiff line numberDiff line change
@@ -227,28 +227,46 @@ This tag helps you install or update Odoo modules without performing a full setu
227227
ansible-playbook playbook.yml --tags "only-modules"
228228
```
229229

230-
Community Roles
231-
---------------
230+
Odoo modules
231+
------------
232232

233233
#### Deploy
234-
To use community roles, you need to deploy this modules in the server. This role manage the modules deployment with `pip`.
234+
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`.
235+
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.
235236

236-
You can define a `requirements.txt` file to manage the modules and ensure the version installed:
237+
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:
237238

239+
```yml
240+
# inventory/group_vars/all.yml
241+
odoo_role_odoo_community_packages:
242+
- odoo11-addon-contract==11.0.2.1.0
243+
- odoo11-addon-contract-sale-invoicing==11.0.1.0.0
244+
- odoo11-addon-contract-variable-qty-timesheet==11.0.1.0.0
245+
- odoo11-addon-contract-variable-quantity==11.0.1.2.1
238246
```
239-
# requirements.txt
240-
odoo11-addon-contract==11.0.2.1.0
241-
odoo11-addon-contract-sale-invoicing==11.0.1.0.0
242-
odoo11-addon-contract-variable-qty-timesheet==11.0.1.0.0
243-
odoo11-addon-contract-variable-quantity==11.0.1.2.1
247+
248+
In some case you want to deploy different versions of the same module to different hosts.
249+
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.
250+
In this case you can define the `odoo_role_odoo_project_packages` variable:
251+
```yml
252+
# inventory/host_vars/production.yml
253+
odoo_role_odoo_project_packages:
254+
- odoo14-my-custom-module==14.0.0.1.0
255+
```
256+
257+
```yml
258+
# inventory/host_vars/development.yml
259+
odoo_role_odoo_project_packages:
260+
- '-e file:///opt/odoo_modules/setup/my_custom_module'
244261
```
245262

246-
> The default the `requirements.txt` file path is `"{{ inventory_dir }}/../files/requirements.txt"`.
263+
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.
264+
If you have a `files/requirements.txt` file defined in your inventory, the two variables just described will not take any effect.
247265

248-
# Install
249-
Once the modules are in the server, you need to install them in the database.
266+
#### Install
267+
Once the modules packages are installed in the server, you need to install them in the Odoo database.
250268

251-
Define a `odoo_role_odoo_community_modules` var with the list of the modules names you want to install.
269+
Define a `odoo_role_odoo_community_modules` variable with the list of the modules names you want to install.
252270

253271
```yml
254272
# inventory/group_vars/all.yml

tasks/community-modules.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
2-
- name: Copy requirements.txt
3-
copy:
4-
src: "{{ odoo_role_community_modules_requirements_path }}"
2+
- name: Create requirements.txt from template
3+
ansible.builtin.template:
4+
src: "{{ lookup('ansible.builtin.first_found', template_sources) }}"
55
dest: "{{ odoo_role_odoo_modules_path }}/requirements.txt"
66
owner: "{{ odoo_role_odoo_user }}"
77
group: "{{ odoo_role_odoo_group }}"
88
mode: 0644
9+
vars:
10+
template_sources:
11+
- "{{ inventory_dir }}/../files/requirements.txt"
12+
- templates/requirements.txt.j2
913
tags: ['community-modules', 'only-modules']
1014

1115
- name: Deploy community roles with pip

tasks/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@
123123
become: true
124124
become_user: "{{ odoo_role_odoo_user }}"
125125
ansible.builtin.shell: >
126-
{{ odoo_role_odoo_python_path }} -m pip list | grep odoo
126+
{{ odoo_role_odoo_python_path }} -m pip show odoo
127127
register: odoo_package_is_installed
128128
failed_when: odoo_package_is_installed.rc not in [0,1]
129129

130130
- name: Install Odoo
131131
become: true
132132
become_user: "{{ odoo_role_odoo_user }}"
133133
shell: "cd {{ odoo_role_odoo_path }} && {{ odoo_role_odoo_python_path }} setup.py install"
134-
when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.stdout == ''
134+
when: odoo_role_desired_tar_download.changed or odoo_role_desired_git_download.changed or odoo_package_is_installed.rc == 1
135135

136136
- name: Populate community db modules
137137
set_fact:

templates/requirements.txt.j2

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# {{ ansible_managed }}
2+
3+
{% for package in odoo_role_odoo_community_packages|default([]) %}
4+
{{ package }}
5+
{% endfor %}
6+
7+
{% for package in odoo_role_odoo_project_packages|default([]) %}
8+
{{ package }}
9+
{% endfor %}

0 commit comments

Comments
 (0)