Skip to content

Commit

Permalink
Merge pull request #56 from coopdevs/feature/multi-db
Browse files Browse the repository at this point in the history
Adapt tasks to N databases
  • Loading branch information
raneq authored Jul 5, 2019
2 parents fef3760 + d7a357f commit caa2321
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ odoo_role_odoo_log_path: /var/log/odoo
odoo_role_odoo_log_level: debug

odoo_role_odoo_db_name: odoo
odoo_role_odoo_dbs: [ "{{ odoo_role_odoo_db_name }}" ]
# This not a DB user password, but a password for Odoo to deal with DB.
odoo_role_odoo_db_admin_password: iT0ohDuoth6ONgahDeepaich0aeka5ul

Expand Down
26 changes: 17 additions & 9 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
owner: "{{ odoo_role_odoo_user }}"
group: "{{ odoo_role_odoo_group }}"
mode: 02775
with_items:
loop:
- "{{ odoo_role_odoo_path }}"
- "{{ odoo_role_odoo_config_path }}"
- "{{ odoo_role_odoo_modules_path }}"
Expand Down Expand Up @@ -110,36 +110,40 @@
become: yes
become_user: "{{ odoo_role_odoo_user }}"
shell: >
psql {{ odoo_role_odoo_db_name }} -tAc
psql {{ item }} -tAc
"SELECT COUNT(*)
FROM information_schema.tables
WHERE table_name='ir_module_module';"
register: db_initialized
with_items: "{{ odoo_role_odoo_dbs }}"

- name: Init Odoo database
- name: "Init Odoo database(s): odoo_role_odoo_dbs"
become: yes
become_user: "{{ odoo_role_odoo_user }}"
command: >
{{ odoo_role_odoo_python_path }} {{ odoo_role_odoo_bin_path }}
-c {{ odoo_role_odoo_config_path }}/odoo.conf
-d {{ odoo_role_odoo_db_name }}
-d {{ item }}
--init base
--stop-after-init
{% if not odoo_role_demo_data %}
--without-demo=all
{% endif %}
--logfile=/dev/stdout
--log-level=warn
when: db_initialized.stdout == "0"
when: db_initialized.results[index].stdout == "0"
notify: restart odoo
with_items: "{{ odoo_role_odoo_dbs }}"
loop_control:
index_var: index

- import_tasks: community-modules.yml

- name: Build the list of new modules to install
become: yes
become_user: "{{ odoo_role_odoo_user }}"
shell: >
psql {{ odoo_role_odoo_db_name }} -tAc
psql {{ item }} -tAc
"SELECT name
FROM (VALUES ('{{ (odoo_role_odoo_core_modules + ',' + odoo_role_community_odoo_modules).split(',') | join(separator) }}'))
AS t (name)
Expand All @@ -150,22 +154,26 @@
register: modules_to_install
vars:
- separator: "'), ('"
with_items: "{{ odoo_role_odoo_dbs }}"

- name: Install only new Odoo modules
become: yes
become_user: "{{ odoo_role_odoo_user }}"
command: >
{{ odoo_role_odoo_python_path }} {{ odoo_role_odoo_bin_path }}
-c {{ odoo_role_odoo_config_path }}/odoo.conf
-d {{ odoo_role_odoo_db_name }}
--init {{ modules_to_install.stdout_lines | join(',') }}
-d {{ item }}
--init {{ modules_to_install.results[index].stdout_lines | join(',') }}
--stop-after-init
{% if not odoo_role_demo_data %}
--without-demo=all
{% endif %}
--logfile=/dev/stdout
--log-level=warn
when: modules_to_install.stdout
when: modules_to_install.results[index].stdout
with_items: "{{ odoo_role_odoo_dbs }}"
loop_control:
index_var: index
notify: restart odoo

- import_tasks: add-service.yml

0 comments on commit caa2321

Please sign in to comment.