From 21263d6b8fa61a0c3bdde4a989d3dac728c37982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com> Date: Fri, 9 Jun 2023 07:22:27 +0200 Subject: [PATCH] [UPD] replace is defined by default() --- handlers/main.yml | 6 +++--- tasks/instance.yml | 16 ++++++++-------- tasks/main.yml | 14 +++++++------- templates/Dockerfile.j2 | 4 ++-- templates/backup.yaml.j2 | 4 ++-- templates/prod.yaml.j2 | 12 ++++++------ 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index ffd6335..9c8acb0 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -10,21 +10,21 @@ name: lefilament/odoo:{{ instance_odoo_version }}_ml source: pull force_source: true - when: not ansible_check_mode and instance.value.odoo_multilingual is defined and instance.value.odoo_multilingual + when: not ansible_check_mode and instance.value.odoo_multilingual | default(false) - name: pull odoo Python3.6 image docker_image: name: lefilament/odoo:{{ instance_odoo_version }}_py3.6 source: pull force_source: true - when: not ansible_check_mode and instance.value.odoo_python36 is defined and instance.value.odoo_python36 + when: not ansible_check_mode and instance.value.odoo_python36 | default(false) - name: pull odoo image docker_image: name: lefilament/odoo:{{ instance_odoo_version }} source: pull force_source: true - when: not ansible_check_mode and (instance.value.odoo_multilingual is not defined or not instance.value.odoo_multilingual) and (instance.value.odoo_python36 is not defined or not instance.value.odoo_python36) + when: not ansible_check_mode and not (instance.value.odoo_multilingual | default(false) or instance.value.odoo_python36 | default(false)) - name: build odoo image docker_compose: diff --git a/tasks/instance.yml b/tasks/instance.yml index dea6262..97860e8 100644 --- a/tasks/instance.yml +++ b/tasks/instance.yml @@ -8,7 +8,7 @@ mode: '0755' - name: container building requirements - when: (item.value.need_build is not defined and item.value.is_prod is defined and not item.value.is_prod) or (item.value.need_build is defined and item.value.need_build) + when: item.value.need_build | default(false) tags: ['never', 'build_odoo'] block: - name: create Odoo docker structure on server in /home/docker/{{ item.key }}/odoo/private @@ -92,7 +92,7 @@ owner: root group: root mode: '0400' - when: git_private_keys is defined + when: git_private_keys | default(false) notify: build odoo image - name: copy Dockerfile to retrieve private repos and extra OCA ones @@ -109,7 +109,7 @@ - build odoo image - name: PROD set image - when: item.value.is_prod is defined and item.value.is_prod and item.value.from_instance is defined + when: item.value.is_prod | default(false) and item.value.from_instance is defined block: - name: PROD check if prod image exists docker_image_info: @@ -130,7 +130,7 @@ owner: root group: root mode: '0400' - when: item.value.is_prod is defined and item.value.is_prod + when: item.value.is_prod | default(false) notify: start odoo container - name: copy test docker-compose service @@ -140,14 +140,14 @@ owner: root group: root mode: '0400' - when: item.value.is_prod is undefined or not item.value.is_prod + when: not (item.value.is_prod | default(false)) notify: start odoo container # -------------------------------------------------- # non-prod restore section # -------------------------------------------------- - name: non-prod restore - when: (item.value.is_prod is undefined or not item.value.is_prod) and inventory_hostname in groups.maintenance_contract + when: not (item.value.is_prod | default(false)) and inventory_hostname in groups.maintenance_contract tags: 'backup_odoo' block: - name: NONPROD copy sql script to be run before restoring db from prod @@ -182,7 +182,7 @@ # prod backup section # -------------------------------------------------- - name: prod backup - when: item.value.is_prod is defined and item.value.is_prod and inventory_hostname in groups.maintenance_contract + when: item.value.is_prod | default(false) and inventory_hostname in groups.maintenance_contract tags: 'backup_odoo' block: - name: PROD copy docker compose for backups @@ -215,7 +215,7 @@ # Remote imports section # -------------------------------------------------- - name: prod import - when: item.value.is_prod is defined and item.value.is_prod and inventory_hostname in groups.maintenance_contract + when: item.value.is_prod | default(false) and inventory_hostname in groups.maintenance_contract block: - name: PROD Push private keys for any external tool connection copy: diff --git a/tasks/main.yml b/tasks/main.yml index ec42316..2566fc6 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -11,7 +11,7 @@ group: root mode: '0400' notify: start odoo whitelists - when: restrict_internet_access and whitelisted_urls is defined + when: restrict_internet_access and whitelisted_urls | default([]) tags: odoo_nonprod, odoo_prod - name: non-prod intance setup @@ -24,7 +24,7 @@ label: "{{ item.key }}" vars: instance_odoo_setup: "{{ odoo_setup_conf[item.value.odoo_setup_version | default(odoo_setup_version)] }}" - when: (item.value.is_prod is not defined or not item.value.is_prod) and (odoo_instance is undefined or item.key == odoo_instance) + when: not (item.value.is_prod | default(false)) and (odoo_instance is undefined or item.key == odoo_instance) - name: prod intance setup include_tasks: instance.yml @@ -33,7 +33,7 @@ label: "{{ item.key }}" vars: instance_odoo_setup: "{{ odoo_setup_conf[item.value.odoo_setup_version | default(odoo_setup_version)] }}" - when: (item.value.is_prod is defined and item.value.is_prod) and (odoo_instance is undefined or item.key == odoo_instance) + when: item.value.is_prod | default(false) and (odoo_instance is undefined or item.key == odoo_instance) # -------------------------------------------------- # Postgres Readonly user @@ -45,7 +45,7 @@ host {{ odoo_prod.db }} {{ odoo_prod.db_user }} 172.16.0.0/12 md5 host postgres {{ odoo_prod.db_user }} 172.16.0.0/12 md5 host {{ odoo_prod.db }} {{ odoo_db_rouser }} all md5 - when: odoo_remote_db_access and odoo_prod is defined and docker_userns_remap + when: odoo_remote_db_access and odoo_prod | default(false) and docker_userns_remap tags: odoo_prod - name: PROD Allow readonly user connection to prod db (no userns_remap) @@ -55,7 +55,7 @@ host {{ odoo_prod.db }} {{ odoo_prod.db_user }} 172.16.0.0/12 md5 host postgres {{ odoo_prod.db_user }} 172.16.0.0/12 md5 host {{ odoo_prod.db }} {{ odoo_db_rouser }} all md5 - when: odoo_remote_db_access and odoo_prod is defined and not docker_userns_remap + when: odoo_remote_db_access and odoo_prod | default(false) and not docker_userns_remap tags: odoo_prod - name: PROD Disable access all rights (with userns_remap) @@ -63,7 +63,7 @@ name: "/var/lib/docker/{{ dockremap_subuid }}.{{ dockremap_subgid }}/volumes/odoo_db/_data/pg_hba.conf" regexp: "^host all all all md5" line: "#host all all all md5" - when: odoo_remote_db_access and odoo_prod is defined and docker_userns_remap + when: odoo_remote_db_access and odoo_prod | default(false) and docker_userns_remap tags: odoo_prod - name: PROD Disable access all rights (no userns_remap) @@ -71,5 +71,5 @@ name: /var/lib/docker/volumes/odoo_db/_data/pg_hba.conf regexp: "^host all all all md5" line: "#host all all all md5" - when: odoo_remote_db_access and odoo_prod is defined and not docker_userns_remap + when: odoo_remote_db_access and odoo_prod | default(false) and not docker_userns_remap tags: odoo_prod diff --git a/templates/Dockerfile.j2 b/templates/Dockerfile.j2 index c07cb13..bfbc8f1 100644 --- a/templates/Dockerfile.j2 +++ b/templates/Dockerfile.j2 @@ -1,5 +1,5 @@ ## Image to get git repos -FROM lefilament/odoo:{{ instance_odoo_setup.odoo_version }}{% if item.value.odoo_python36 is defined and item.value.odoo_python36 %}_py3.6{% endif %}{% if item.value.odoo_multilingual is defined and item.value.odoo_multilingual %}_ml{% endif %} as odoo_addons +FROM lefilament/odoo:{{ instance_odoo_setup.odoo_version }}{% if item.value.odoo_python36 | default(false) %}_py3.6{% endif %}{% if item.value.odoo_multilingual | default(false) %}_ml{% endif %} as odoo_addons LABEL stage=builder USER root # Install GitLab private keys @@ -16,7 +16,7 @@ RUN /opt/odoo/private/fetch_repos_addons RUN /opt/odoo/private/fetch_repos ## Final image -FROM lefilament/odoo:{{ instance_odoo_setup.odoo_version }}{% if item.value.odoo_python36 is defined and item.value.odoo_python36 %}_py3.6{% endif %}{% if item.value.odoo_multilingual is defined and item.value.odoo_multilingual %}_ml{% endif %} as final +FROM lefilament/odoo:{{ instance_odoo_setup.odoo_version }}{% if item.value.odoo_python36 | default(false) %}_py3.6{% endif %}{% if item.value.odoo_multilingual | default(false) %}_ml{% endif %} as final USER root COPY --from=odoo_addons --chown=odoo:odoo /opt/odoo/private_addons /opt/odoo/private_addons COPY --from=odoo_addons --chown=odoo:odoo /opt/odoo/additional_addons /opt/odoo/additional_addons diff --git a/templates/backup.yaml.j2 b/templates/backup.yaml.j2 index baeebde..5ffa14b 100644 --- a/templates/backup.yaml.j2 +++ b/templates/backup.yaml.j2 @@ -23,7 +23,7 @@ services: volumes: - {{ item.key }}{{ account.key }}_backup_cache:/root/.cache/duplicity/:z - {{ item.key }}_filestore:/mnt/backup/src/odoo:z -{% if item.value.metabase is defined and item.value.metabase %} +{% if item.value.metabase | default(false) %} - {{ item.key }}_metabase:/mnt/backup/src/metabase:z {% endif %} networks: @@ -43,7 +43,7 @@ volumes: {{ item.key }}{{ account.key }}_backup_cache: {{ item.key }}_filestore: external: true -{% if item.value.metabase is defined and item.value.metabase %} +{% if item.value.metabase | default(false) %} {{ item.key }}_metabase: external: true {% endif %} diff --git a/templates/prod.yaml.j2 b/templates/prod.yaml.j2 index e96e1fb..b030856 100644 --- a/templates/prod.yaml.j2 +++ b/templates/prod.yaml.j2 @@ -1,7 +1,7 @@ version: "2.1" services: odoo: -{% if item.value.need_build is defined and item.value.need_build %} +{% if item.value.need_build | default(false) %} build: context: ./odoo {% endif %} @@ -69,7 +69,7 @@ services: {% endif %} labels: co.elastic.logs/module: postgresql -{% if item.value.odoo_remote_db_access is defined and item.value.odoo_remote_db_access %} +{% if item.value.odoo_remote_db_access | default(false) %} networks: default: public: @@ -162,7 +162,7 @@ services: {% endfor %} {% endif %} -{% if item.value.metabase is defined and item.value.metabase %} +{% if item.value.metabase | default(false) %} metabase: image: metabase/metabase container_name: {{ item.key }}_metabase @@ -212,7 +212,7 @@ networks: inverseproxy_app: external: true {% endif %} -{% if item.value.metabase is defined and item.value.metabase %} +{% if item.value.metabase | default(false) %} inverseproxy_bi: external: true {% endif %} @@ -242,7 +242,7 @@ networks: encrypted: 1 {% endif %} {% endif %} -{% if item.value.odoo_remote_db_access is defined and item.value.odoo_remote_db_access %} +{% if item.value.odoo_remote_db_access | default(false) %} public: {% endif %} @@ -252,6 +252,6 @@ volumes: {% if mailname is defined %} smtp: {% endif %} -{% if item.value.metabase is defined and item.value.metabase %} +{% if item.value.metabase | default(false) %} metabase: {% endif %} -- GitLab