From e5dfbf3df8a8e1491798af22b414cfbab5faa201 Mon Sep 17 00:00:00 2001 From: hayyan Date: Wed, 9 May 2018 21:32:32 +0200 Subject: [PATCH 1/2] init push ansible lxc-containers --- README_FOR_SUNFLOWER_TEAM.md | 258 ++++++++++++++++++++++++++++++ defaults/main.yml | 97 ++++++++--- files/odoo.service | 10 ++ handlers/main.yml | 17 +- tasks/config_lxd_container.yml | 73 +++++++++ tasks/config_nginx_proxy.yml | 91 +++++++++++ tasks/create_lxd_container.yml | 64 ++++++++ tasks/direct_installation.yml | 33 ++++ tasks/install.yml | 121 +++++++++++--- tasks/install_buildout.yml | 92 ++++++++++- tasks/install_npm.yml | 6 +- tasks/install_pip.yml | 10 +- tasks/install_ssh.yml | 5 +- tasks/lxd_postgresql.yml | 41 +++++ tasks/main.yml | 73 ++++++--- tasks/reportlab.yml | 2 +- tasks/service.yml | 74 ++++++++- tasks/wkhtmltox.yml | 1 + tasks/work_into_lxd_container.yml | 54 +++++++ templates/odoo-11.0.init | 82 +++++++++- vars/Ubuntu-16_Odoo-10.yml | 2 +- vars/Ubuntu-16_Odoo-11.yml | 3 +- vars/Ubuntu-16_Odoo-8.yml | 3 +- vars/Ubuntu-16_Odoo-9.yml | 2 +- vars/main.yml | 5 + 25 files changed, 1126 insertions(+), 93 deletions(-) create mode 100644 README_FOR_SUNFLOWER_TEAM.md create mode 100644 files/odoo.service create mode 100644 tasks/config_lxd_container.yml create mode 100644 tasks/config_nginx_proxy.yml create mode 100644 tasks/create_lxd_container.yml create mode 100644 tasks/direct_installation.yml create mode 100644 tasks/lxd_postgresql.yml create mode 100644 tasks/work_into_lxd_container.yml mode change 120000 => 100644 templates/odoo-11.0.init diff --git a/README_FOR_SUNFLOWER_TEAM.md b/README_FOR_SUNFLOWER_TEAM.md new file mode 100644 index 0000000..2018bf3 --- /dev/null +++ b/README_FOR_SUNFLOWER_TEAM.md @@ -0,0 +1,258 @@ +# Odoo + +Ansible is an IT automation tool. so we deploy ansible-playbook to automate install and config odoo in LXD container. +ansible layout: + +## ansible work directory: +in ansible work directory we moust have three files (ansible.cfg; hosts; playbook.yml) and one folder (moust have 'roles' name) +inclod 'roles' folder we moust have role folder like 'ansible-odoo' in this folder moust we have on folder at list have 'tasks' name and aditional folders like (default; vars; files etc) + +* **ansible.cfg**: is config file so in this toturial we bouild ansible cfg lines to be: + +* **hosts**: hosts file is file stor the names of nodes can we access to it by ssh or lxd protocol or any protocol ansibile support it + +* **playbook.yml**: playbook.yml is where you basically tell Ansible: please install roles on some nodes. and we can manipulate ansible roles by put some varibles in playbook.yml and we can store many playbook.yml files in ansible works directory that with different name indicates why we use it like (buildout.yml, creat_container.yml; config_db.yml etc) and run single file in single comand as what we need + +* **defaults/main.yml**: +This directory contains defaults for variables used in roles. I encourage you to discover every variable we put in our role + +* **tasks/main.yml**: +This file is the tasks entry point. the best way to discover our roles in this tutorial is starting analysis tasks in this file + + + + +* **files/**: +This directory holds files can be copied as-is on the remote nodes. + +* **vars**: +this folder include variables preference allow tasks to choose between it occurred play satiation + +## Supported versions and systems + +| System / Odoo | 8.0 | 9.0 | 10.0 | 11.0 | LXD | +|---------------|-----|-----|------|------|------| +| Debian 8 | yes | yes | yes | - | - | +| Debian 9 | yes | yes | yes | yes | - | +| Ubuntu 14.04 | yes | yes | yes | - | yes | +| Ubuntu 16.04 | yes | yes | yes | yes | yes | + +## Example (Playbook) + +to use this ansible roles we must copy /etc/ansible folder to home directory then edit ansible.cfg file clear all lins in it and put this line: +[defaults] +inventory = hosts +enable_task_debugger = True +then edit hosts file clear all lins in it and put this line: +localhost + +then git clone our repository in roles folder: +git clone +then touch default.yml in ansible works directory and put this lines into it: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo +``` + +then run this command +ansible-playbook -K default.yml + +by this command ansible run in default variables so the roles will do that steps: + +1- create LXD container: 'lxdcontainer' and put "lxdcontainer ansible_connection=lxd" line in ansible inventory hosts file 'hosts' to make 'lxdcontainer' available in ansible enviroment + +2- copy id_rsa from the .ssh folder in home server user folder: /home/odoo/.ssh/id_rsa to the .ssh folder in home container user folder: /home/ubuntu/.ssh/ + +3- change container network type from DHCP mode to static IP maode with same 'lxdcontainer' setting that given it by DHCP. + +4- install postgresql into lxdcontainer, and creat user: 'ubuntu' into postgresql with password: 'password' and with (NOCREATE, NOSUBERUSER) rights. + +5- creat database: 'odoodatabase', and grant 'ubuntu' to be owner of 'odoodatabase'. + +6- install some pkg: (sudo; git; mercurial; python-pip; python-psycopg2; nl_NL.UTF-8) in LXD container OS + +7- download bransh 9.0 from sunflower repository "https://github.com/sunflowerit/custom-installations/tree/9.0-custom-standard" + +8- install some pkg: ( build-essential; python-dev; libxml2-dev; libxslt1-dev; libpq-dev; libldap2-dev; libsasl2-dev; libopenjp2-7-dev; libjpeg-turbo8-dev; libtiff5-dev; libfreetype6-dev; liblcms2-dev; libwebp-de) + +9- creat /home/ubuntu/odoo/local.cfg in container OS. the default containt in local.cfg is: +``` + [buildout]" + extends = odoo8-standard.cfg + + [odoo] + options.admin_passwd = admin + options.db_host = localhost + options.db_name = odoodatabase + options.db_port = 5432 + options.db_user = ubuntu + options.db_password = password + options.xmlrpc_port = 8069 + options.longpolling_port = 8072 +``` +10- run this command: /usr/bin/python /home/ubuntu/odoo/bootstrap.py -c /home/ubuntu/odoo/local.cfg --buildout-version 2.11.4 + +11- install setuptools version: 38.1.0 + +12- download https://raw.githubusercontent.com/odoo/odoo/8.0/requirements.txt + +13- install pip pkg that in requirements.txt + +14- run this command: /home/ubuntu/odoo/bin/buildout -c /home/ubuntu/odoo/local.cfg + +15- then install (less; less-plugin-clean-css; phantomjs-prebuilt) if we build odoo 9.0 or 10.0 + +16- Download wkhtmltox + +17- Install wkhtmltox dependencies and wkhtmltox 'generic package' + +18- Download the ReportLab barcode fonts then unzip it + +19- Generate odoo service files + +20- create /etc/nginx/sites-available/lxdcontainer.sunflowerodoo.nl, the default containt in lxdcontainer.sunflowerodoo.nl is: + server { + listen 80; + server_name lxdcontainer.sunflowerodoo.nl; + + client_max_body_size 200M; + + proxy_connect_timeout 6000s; + proxy_send_timeout 6000s; + proxy_read_timeout 6000s; + send_timeout 6000s; + + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; + + location / { + proxy_pass http://{{ odoo_ip }}:8069; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Scheme $scheme; + proxy_connect_timeout 600; + proxy_send_timeout 600; + proxy_read_timeout 600; + + } + + location /lonngpolling { + proxy_pass http://{{ odoo_ip }}:8072; + } + + } + + +21- Make link in /etc/nginx/sites-enabled/lxdcontainer.sunflowerodoo.nl to /etc/nginx/sites-available/lxdcontainer.sunflowerodoo.nl + +22- try to reload nginx by this command: nginx -t && nginx -s reload + +now we can tchange ansible-playbook behavier by put some variable value in blaybook.yml +for example +to make a new container and giv it simpleodoo10 and install odoo 10.0 inside this container from 10.0-custom-standard bransh and config nginx to make this container available in simpleodoo10.sunflowerodoo.nl we touch odoo_10_default.yml in ansible works directory and edit it to be: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo + odoo_version: 10.0 + odoo_config_db_name: odoodatabase + lxd_container_name: simpleodoo10 + branch: 10.0-custom-standard +``` + +then we run this command +ansible-playbook -K odoo_10_default.yml + +to create a new container 'cleanlxdcontainer' install postgres with and create 'simpleuser' user with 'TlTtLLtt' password in database and grant it to have CREATEDB,SUPERUSER without creat database and without download odoo and without install odoo and without config nginx we touch simple_lxd.yml and edit it to be: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo + lxd_container_name: cleanlxdcontainer + new_postgresql_db: false + odoo_config_db_user: simpleuser + odoo_config_db_passwd: TlTtLLtt + odoo_config_db_user_righs: "CREATEDB,SUPERUSER" + buildout_step: false + nginx_step: false +``` +then we run this command +ansible-playbook -K simple_lxd.yml + +for example we can move some data base to 'cleanlxdcontainer' and then we need to install odoo 10.0 from bransh 9.0-custom-standard with custom buildout file we have before like custome.cfg and we plane to use buildout version 2.8.0 and make build it to use the database 'somedatabase' we moved it to container manaiualy befor and we plan to ignore installing (less; less-plugin-clean-css; phantomjs-prebuilt; wkhtmltox; ReportLab barcode fonts) and we need to make odoo able on xmlrpc port '8090' and on longpolling port '8095' and config nginx to make this container availabe in test.sunflowerodoo.nl we must put custom.cfg in roles/files/odoo_config_files/ and edit simple_lxd.yml in ansible works directory to be: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo + lxd_container_name: cleanlxdcontainer + lxd_step: false + odoo_version: 10.0 + buildout_config_file: custome.cfg + github_account: [ your accont on github allow you to acces to sunflower instance ] + github_account_name: [ your name ] + odoo_buildout_version: 2.8.0 + odoo_config_db_user: simpleuser + odoo_config_db_passwd: TlTtLLtt + app_after_buildout: false + buildout_step: true + nginx_step: true + nginx_subdomain: test + odoo_config_xmlrpc_port: 8090 + odoo_config_longpolling_port: 8095 +``` +then we run this command +ansible-playbook -K simple_lxd.yml + +if we plane to create 'customuser' container and creat 'customer' system user with 'wQrEyTuY' password and with vertual enviroment in that container and install postgresql with default 'odoodatabase' database and default database user and password and downlowad odoo 8.0 from bransh 9.0-custom-standard but without run bootstrap and without run buildout and make it avialable at customuser.sunflowerserver.nl we touch customer.yml and edit it to be: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo + odoo_version: 8.0 + lxd_container_name: customuser + new_lxd_container: False + odoo_user: customer + odoo_user_passwd: wQrEyTuY + env_type: true + run_bootstrap: false + run_buildout: false + nginx_domain: sunflowerserver.nl +``` +then we run this command +ansible-playbook -K customer.yml + +now if we plan to install default odoo 10.0 directly on server and creat 'odoouser' system user with 'SaFdHgKj' password for that and install odoo 10.0 in vertual inviroment and config nginx to make this container available at odoo10local.sunflowerodoo.nl we touch odoo10local.yml and edit it to be: +```yaml +- name: Odoo + hosts: localhost + connection: local + become: yes + roles: + - role: ansible-odoo + odoo_version: 10.0 + lxd_type: false + odoo_user: odoouser + odoo_user_passwd: SaFdHgKj + env_type: true + nginx_subdomain: odoo10local + odoo_config_xmlrpc_port: 8016 + odoo_config_longpolling_port: 8019 +``` + diff --git a/defaults/main.yml b/defaults/main.yml index c270c5c..c1bab87 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,10 +1,62 @@ -ansible_ssh_pipelining: true +host_user: odoo #Your account on LXD host server +odoo_user: ubuntu #Your account to install odoo in odoo host +lxd_type: True #True for make a new LXD container and install odoo inside it, False to install odoo directly on server +lxd_container_name: test #The name you giv to a new LXD container +new_lxd_container: True #This condition to be carefull about exist containers when you run ansible-playbook +lxd_step: True #True to create a new LXD container, False if LXD container is exist and configure +container_nameservers: " " #The DNS address in your network +postgresql_step: True #True to install PostgreSQL and create a new database if new_postgresql_db==True, False to ignore that +new_postgresql_db: True #True to create a new database if postgresql_step==True, False to ignore that +odoo_install_type: buildout #Buildout or PIP or Standard +buildout_step: True #If you aim to create container with out odoo choose False +odoo_version: 8.0 # +sunflower_repo_url: "git@github.com:sunflowerit/custom-installations.git" #The repository site link of odoo +sunflower_repo: True #True for Sunflower repository, False for other repository +branch: 9.0-custom-standard #The branch of Sunflower repository if you choose it +github_account: anonymous #Your account in github site +github_account_name: anonymous #Your account name in github site +odoo_config_admin_passwd: admin #Admin password for odoo +odoo_config_db_host: localhost #The name of server is hosts odoo database +odoo_config_db_name: odoodatabase #The name of odoo database +odoo_config_db_user: "{{ odoo_user }}" #The odoo account in PostgreSQL +odoo_config_db_passwd: password #The passowrd of odoo account in PostgreSQL +odoo_config_db_user_righs: "NOCREATEDB,NOSUPERUSER" #The right what odoo account in Postgresql have +odoo_config_db_port: 5432 #The port of database into PostgreSQL +odoo_config_xmlrpc_port: 8069 #The XMLRPC port of odoo +odoo_config_longpolling_port: 8072 #The longpolling port of odoo +odoo_service: odoo #The name of odoo service in odoo OS host +env_type: False #True to install odoo into virtual environment, False to install odoo without virtual environment +odoo_buildout_venv_path: "{{ odoo_workdir }}/sandbox" #The virtual environment folder +odoo_buildout_version: 2.11.4 #The version of Buildout script +odoo_workdir: "/home/{{ odoo_user }}/odoo" #The folder where odoo files tree +odoo_buildout_bin_path: "{{ odoo_workdir }}/bin/buildout" #The path where Buildout script +odoo_buildout_bootstrap_path: "{{ odoo_workdir }}/bootstrap.py" #The path where Bootstrap script +odoo_buildout_bootstrap_cmd: "{{ odoo_buildout_venv_path }}/bin/python {{ odoo_buildout_bootstrap_path }} -c {{ odoo_buildout_config_path }} --buildout-version {{ odoo_buildout_version }}" #The command to run bootstrap script +buildout_config_file: odoo{{ odoo_version | int }}-standard.cfg #The name of buildout config file +odoo_buildout_config_path: "{{ odoo_workdir }}/{{ buildout_config_file }}" #The path of buildout config file +odoo_logdir: "/var/log/{{ odoo_user }}" #The folder of odoo log files +odoo_logfile: "{{ ansible_service_mgr != 'systemd' and ('/'.join([odoo_logdir, odoo_service]) + '.log') or ''}}" #The odoo log file +run_bootstrap: True #True to run bootstrap into buildout step, false to ignore that +app_before_buildout: True #True to install recruitments pkg before run buildout, False to ignore that +run_buildout: True #True to run buildout into buildout step, False to ignore that +odoo_buildout_odoo_bin_path: "{{ odoo_workdir }}/bin/start_odoo" #The path of script to start odoo +app_after_buildout: True #True to install recruitments pkg after run buildout, False to ignore that +nginx_step: true #True to include LXD container IP in NGINX proxy reserve, False to ignore that +odoo_ip: 127.0.0.1 #The IP address of odoo +nginx_domain: sunflowerodoo.nl #The parent domain of LXD container URL +nginx_subdomain: "{{ lxd_container_name }}" #The subdomain to access odoo through NGINX domain -odoo_install_type: standard # standard, buildout -odoo_version: 11.0 -odoo_service: odoo -odoo_user: odoo -odoo_user_passwd: "*" # http://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module + + + + +ansible_ssh_pipelining: True + + # standard, buildout + + + +odoo_user_passwd: 11223344 # http://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module odoo_user_update_password: always odoo_user_shell: /bin/bash odoo_user_system: False @@ -12,9 +64,8 @@ odoo_init: True odoo_init_env: {} #VAR1: value1 #VAR2: value2 -odoo_logdir: "/var/log/{{ odoo_user }}" -odoo_logfile: "{{ ansible_service_mgr != 'systemd' and ('/'.join([odoo_logdir, odoo_service]) + '.log') or ''}}" -odoo_workdir: "/home/{{ odoo_user }}/odoo" + + odoo_rootdir: "{{ odoo_install_type == 'buildout' and '/home/'+odoo_user+'/odoo/parts/odoo' or '/home/'+odoo_user+'/odoo/server' }}" # Project repository to deploy @@ -44,19 +95,19 @@ odoo_force_config: True odoo_config_addons_path: - "/home/{{ odoo_user }}/odoo/server/{{ (odoo_version | int) < 10 and 'openerp' or 'odoo' }}/addons" - "/home/{{ odoo_user }}/odoo/server/addons" -odoo_config_admin_passwd: admin + odoo_config_auto_reload: False odoo_config_csv_internal_sep: ',' odoo_config_data_dir: "/home/{{ odoo_user }}/.local/share/Odoo" -odoo_config_db_host: False + odoo_config_db_host_user: "{{ ansible_user }}" odoo_config_db_maxconn: 64 -odoo_config_db_name: False -odoo_config_db_passwd: False -odoo_config_db_port: False + + + odoo_config_db_sslmode: prefer # >= 11.0 odoo_config_db_template: template1 -odoo_config_db_user: "{{ odoo_user }}" + odoo_config_dbfilter: '.*' odoo_config_debug_mode: False # <= 9.0 odoo_config_pidfile: None @@ -76,7 +127,7 @@ odoo_config_log_db: False odoo_config_log_level: info odoo_config_logfile: None odoo_config_logrotate: False -odoo_config_longpolling_port: 8072 + odoo_config_osv_memory_age_limit: 1.0 odoo_config_osv_memory_count_limit: False odoo_config_max_cron_threads: 2 @@ -96,7 +147,7 @@ odoo_config_without_demo: False odoo_config_workers: 0 odoo_config_xmlrpc: True # <= 10.0 odoo_config_xmlrpc_interface: '' # <= 10.0 -odoo_config_xmlrpc_port: 8069 # <= 10.0 + # <= 10.0 odoo_config_xmlrpcs: True # <= 8.0 odoo_config_xmlrpcs_interface: '' # <= 8.0 odoo_config_xmlrpcs_port: 8071 # <= 8.0 @@ -111,13 +162,10 @@ odoo_pip_requirements_url: "file:///home/{{ odoo_user }}/requirements.txt" odoo_pip_odoo_bin_path: "{{ odoo_pip_venv_path }}/bin/{{ (odoo_version | int) < 10 and 'odoo.py' or 'odoo' }}" # Buildout installation options (odoo_install_type == 'buildout') -odoo_buildout_version: 2.10.0 -odoo_buildout_venv_path: "{{ odoo_workdir }}/sandbox" -odoo_buildout_bootstrap_path: "{{ odoo_workdir }}/bootstrap.py" -odoo_buildout_bootstrap_cmd: "{{ odoo_buildout_venv_path }}/bin/python {{ odoo_buildout_bootstrap_path }} -c {{ odoo_buildout_config_path }} --buildout-version {{ odoo_buildout_version }}" -odoo_buildout_bin_path: "{{ odoo_workdir }}/bin/buildout" -odoo_buildout_config_path: "{{ odoo_workdir }}/buildout.cfg" -odoo_buildout_odoo_bin_path: "{{ odoo_workdir }}/bin/start_odoo" + + + + odoo_buildout_extra_dependencies: [] # Extra Debian packages required # to run your Buildout recipe @@ -140,3 +188,4 @@ odoo_user_ssh_known_hosts: [] # FIXME: 'odoo_user_sshkeys' option (and the underlying task) needs refactoring # to handle the state of SSH public keys (present/absent). odoo_user_sshkeys: "" # ./path/to/public_keys/* + diff --git a/files/odoo.service b/files/odoo.service new file mode 100644 index 0000000..de33726 --- /dev/null +++ b/files/odoo.service @@ -0,0 +1,10 @@ +[Unit] +Description=Odoo +After=postgresql.service +[Service] +Type=simple +User=ubuntu +ExecStart=/home/ubuntu/odoobuildout/bin/start_odoo + +[Install] +WantedBy=default.target diff --git a/handlers/main.yml b/handlers/main.yml index a4f508a..e700dcf 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,12 +1,25 @@ --- +- name: Restart LXD-Odoo + delegate_to: "{{ lxd_container_name }}" + service: + name: "{{ odoo_service }}" + state: restarted + when: odoo_init == True and lxd_type == True + - name: Restart Odoo service: name: "{{ odoo_service }}" state: restarted - when: odoo_init == True + when: odoo_init == True and lxd_type == False + +- name: Reload LXD-Systemd + delegate_to: "{{ lxd_container_name }}" + systemd: + daemon-reload: yes + when: ansible_service_mgr == 'systemd' and lxd_type == True - name: Reload Systemd systemd: daemon-reload: yes - when: ansible_service_mgr == 'systemd' + when: ansible_service_mgr == 'systemd' and lxd_type == False diff --git a/tasks/config_lxd_container.yml b/tasks/config_lxd_container.yml new file mode 100644 index 0000000..5982ee2 --- /dev/null +++ b/tasks/config_lxd_container.yml @@ -0,0 +1,73 @@ +--- + +- name: Git container DHCP ip + become: yes + become_user: root + delegate_to: "{{ lxd_container_name }}" + shell: "/sbin/ifconfig eth0 | grep 'inet addr' | cut -d ':' -f2 | awk '{print $1}'" + register: container_ip + when: lxd_step + +- name: Git container DHCP Broadcast + become: yes + become_user: root + delegate_to: "{{ lxd_container_name }}" + shell: "/sbin/ifconfig eth0 | grep 'inet addr' | cut -d ':' -f3 | awk '{print $1}'" + register: container_broadcast + when: lxd_step + +- name: Git container DHCP Netmask + become: yes + become_user: root + delegate_to: "{{ lxd_container_name }}" + shell: "/sbin/ifconfig eth0 | grep 'inet addr' | cut -d ':' -f4 | awk '{print $1}'" + register: container_netmask + when: lxd_step + +- name: Git container DHCP gateway + become: yes + become_user: root + delegate_to: "{{ lxd_container_name }}" + shell: "/sbin/ip route |grep '^default' | awk '/eth0/' | cut -d' ' -f3" + register: container_gateway + when: lxd_step + +- name: Remove /etc/network/interfaces + file: + path: /etc/network/interfaces + state: absent + become_user: root + +- name: Touch /etc/network/interfaces + become_user: root + file: + path: /etc/network/interfaces + state: touch + +- name: Config /etc/network/interfaces + become_user: root + lineinfile: + dest: /etc/network/interfaces + line: "{{ item }}" + with_items: + - auto lo + - iface lo inet loopback + - " " + - auto eth0 + - iface eth0 inet static + - "address {{ container_ip.stdout }}" + - "netmask {{ container_netmask.stdout }}" + - "broadcast {{ container_broadcast.stdout }}" + - "gateway {{ container_gateway.stdout }}" + - "dns-nameservers {{ container_gateway.stdout }} {{ container_nameservers }}" + +- name: Restart networking service + become: yes + become_user: root + shell: | + ifdown eth0 + ifup eth0 + service networking restart + + + diff --git a/tasks/config_nginx_proxy.yml b/tasks/config_nginx_proxy.yml new file mode 100644 index 0000000..7e17e0b --- /dev/null +++ b/tasks/config_nginx_proxy.yml @@ -0,0 +1,91 @@ +--- + +- name: Check {{ nginx_subdomain }}.{{ nginx_domain }} file if exists + become_user: root + stat: + path: /etc/nginx/sites-available/{{ nginx_subdomain }}.{{ nginx_domain }} + register: stat_result + +- name: Generate random string + become_user: root + shell: head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13 ; echo '' + register: random_string + when: stat_result.stat.exists == True + +- name: rename {{ nginx_subdomain }}.{{ nginx_domain }} to {{ nginx_subdomain }}.{{ random_string.stdout }} + become_user: root + shell: mv /etc/nginx/sites-available/{{ nginx_subdomain }}.{{ nginx_domain }} /etc/nginx/sites-available/{{ nginx_subdomain }}.{{ random_string.stdout }} + when: stat_result.stat.exists == True + +- name: Touch {{ nginx_subdomain }}.{{ nginx_domain }} + become_user: root + file: + path: /etc/nginx/sites-available/{{ nginx_subdomain }}.{{ nginx_domain }} + state: touch + +- name: Set odoo ip + set_fact: odoo_ip="{{ container_ip.stdout }}" + when: lxd_type == True and lxd_step == True + +- name: Git container ip + delegate_to: "{{ lxd_container_name }}" + become: yes + become_user: root + shell: "/sbin/ifconfig eth0 | grep 'inet addr' | cut -d ':' -f2 | awk '{print $1}'" + register: ip_contents + when: lxd_type == True and lxd_step == False + +- name: Set odoo ip + set_fact: odoo_ip="{{ ip_contents.stdout }}" + when: lxd_type == True and lxd_step == False + +- name: Config sites-available/{{ nginx_subdomain }}.{{ nginx_domain }} + become_user: root + lineinfile: + dest: /etc/nginx/sites-available/{{ nginx_subdomain }}.{{ nginx_domain }} + line: "{{ item }}" + with_items: + - "server {" + - " listen 80;" + - " server_name {{ nginx_subdomain }}.{{ nginx_domain }};" + - "\n" + - " client_max_body_size 200M;" + - "\n" + - " proxy_connect_timeout 6000s;" + - " proxy_send_timeout 6000s;" + - " proxy_read_timeout 6000s;" + - " send_timeout 6000s;" + - "\n" + - " proxy_set_header Host $http_host;" + - " proxy_set_header X-Real-IP $remote_addr;" + - " proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;" + - "\n" + - " location / { " + - " proxy_pass http://{{ odoo_ip }}:{{ odoo_config_xmlrpc_port }};" + - " proxy_set_header Host $host;" + - " proxy_set_header X-Real-IP $remote_addr;" + - " proxy_set_header X-Scheme $scheme;" + - " proxy_connect_timeout 600;" + - " proxy_send_timeout 600;" + - " proxy_read_timeout 600;" + - "\n" + - " }" + - "\n" + - " location /lonngpolling { " + - " proxy_pass http://{{ odoo_ip }}:{{ odoo_config_longpolling_port }};" + - " } " + - "\n" + - "} " + + +- name: Make link to sites-enabled + become_user: root + file: + src: "/etc/nginx/sites-available/{{ nginx_subdomain }}.{{ nginx_domain }}" + dest: "/etc/nginx/sites-enabled/{{ nginx_subdomain }}.{{ nginx_domain }}" + state: link + + +- name: Reload nginx + become: yes + shell: nginx -t && nginx -s reload diff --git a/tasks/create_lxd_container.yml b/tasks/create_lxd_container.yml new file mode 100644 index 0000000..c642e8d --- /dev/null +++ b/tasks/create_lxd_container.yml @@ -0,0 +1,64 @@ +--- + +- name: Create a started container + lxd_container: + name: "{{ lxd_container_name }}" + state: started + source: + type: image + mode: pull + server: https://images.linuxcontainers.org + protocol: lxd + alias: ubuntu/xenial/amd64 + profiles: ["default"] + wait_for_ipv4_addresses: true + timeout: 600 + +- name: Add new continer name in hosts file + become_user: "{{ host_user }}" + lineinfile: + dest: hosts + line: "{{ lxd_container_name }} ansible_connection=lxd" + +- name: Refresh hosts + meta: refresh_inventory + +- name: check python is installed in container + delegate_to: "{{ lxd_container_name }}" + connection: lxd + raw: dpkg -s python + register: python_install_check + failed_when: python_install_check.rc not in [0, 1] + changed_when: false + +- name: install python in container + delegate_to: "{{ lxd_container_name }}" + raw: apt-get install -y python + when: python_install_check.rc == 1 + +- name: Make "{{ odoo_user }}" home folder + delegate_to: "{{ lxd_container_name }}" + file: + path: /home/{{ odoo_user }} + state: directory + mode: 0777 + owner: ubuntu + group: ubuntu + when: odoo_user != 'ubuntu' and sunflower_repo == True + +- name: Make ssh folder + delegate_to: "{{ lxd_container_name }}" + file: + path: /home/{{ odoo_user }}/.ssh + state: directory + mode: 0700 + owner: ubuntu + group: ubuntu + when: sunflower_repo == True + +- name: Copy id_rsa key + become_user: "{{ host_user }}" + become: yes + shell: | + lxc file push /home/{{ host_user }}/.ssh/id_rsa {{lxd_container_name}}/home/{{ odoo_user }}/.ssh/ + when: sunflower_repo == True diff --git a/tasks/direct_installation.yml b/tasks/direct_installation.yml new file mode 100644 index 0000000..9fb9c5f --- /dev/null +++ b/tasks/direct_installation.yml @@ -0,0 +1,33 @@ +--- + +- name: Set variables depending on the platform and the version of Odoo + include_vars: "{{ item }}" + with_first_found: + - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version | int}}_Odoo-{{ odoo_version | int }}.yml" + tags: + - always + +- import_tasks: install.yml + tags: + - odoo + - odoo_install + +- import_tasks: wkhtmltox.yml + tags: + - odoo + - odoo_wkhtmltox + +- import_tasks: reportlab.yml + tags: + - odoo + - odoo_reportlab + +- import_tasks: postgresql.yml + tags: + - odoo + - odoo_postgresql + +- import_tasks: service.yml + tags: + - odoo + - odoo_service diff --git a/tasks/install.yml b/tasks/install.yml index fcca158..012f5df 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -2,12 +2,20 @@ - name: Install required tools apt: pkg={{ item }} - state=installed + state=present update_cache={{ odoo_apt_update_cache }} cache_valid_time={{ odoo_apt_cache_valid_time }} with_items: "{{ odoo_required_tools }}" tags: - odoo_required_tools + when: app_before_buildout + +- name: Ensure a locale exists + become_user: root + locale_gen: + name: nl_NL.UTF-8 + state: present + when: app_before_buildout == True and sunflower_repo == True - name: Add Odoo system user user: @@ -18,37 +26,102 @@ system: "{{ odoo_user_system }}" tags: - odoo_user + when: not lxd_type -- name: Configure SSH for the Odoo user - import_tasks: install_ssh.yml - tags: - - odoo_install_ssh +- name: Make ssh folder + file: + path: /home/{{ odoo_user }}/.ssh + state: directory + mode: 0700 + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + when: sunflower_repo == True and lxd_type == False -- name: Create log directory - file: path={{ odoo_logdir }} state=directory - owner={{ odoo_user }} group={{ odoo_user }} force=no - tags: - - odoo_log +- name: copy id_rsa file + copy: + src: id_rsa + dest: /home/{{ odoo_user }}/.ssh/ + force: yes + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + mode: 0600 + when: sunflower_repo == True and lxd_type == False -- name: Project repository already cloned? - stat: path={{ odoo_repo_dest }} - register: project_path - tags: - - odoo_project +- name: chmode /home/{{ odoo_user }} + file: + path: /home/{{ odoo_user }} + mode: 0755 + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + when: odoo_user != 'ubuntu' and sunflower_repo == True -- name: Clone project repository (Mercurial) +- name: chmode /home/{{ odoo_user }}/.ssh + file: + path: /home/{{ odoo_user }}/.ssh + mode: 0700 + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + when: odoo_user != 'ubuntu' and sunflower_repo == True + +- name: chmode /home/{{ odoo_user }}/.ssh/id_rsa + file: + path: /home/{{ odoo_user }}/.ssh/id_rsa + mode: 0600 + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + when: sunflower_repo == True + +- name: Touch Known_hosts + become_user: root + file: + path: /home/{{ odoo_user }}/.ssh/known_hosts + state: touch + mode: 0755 + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + when: sunflower_repo + +- name: Add github key to known_hosts + become_user: "{{ odoo_user }}" + shell: | + ssh-keygen -F github.com || ssh-keyscan github.com >> /home/{{ odoo_user }}/.ssh/known_hosts + when: sunflower_repo + +- name: Config git account become: yes become_user: "{{ odoo_user }}" - hg: repo={{ odoo_repo_url }} - dest={{ odoo_repo_dest }} - revision={{ odoo_repo_rev | string }} - when: odoo_repo_type == 'hg' and odoo_repo_url - and (odoo_repo_update or (project_path.stat.exists == False)) + shell: | + git config --global user.email "{{ github_account }}" + git config --global user.name "{{ github_account_name }}" + when: sunflower_repo + + +- name: Ensure python-pip is installed + apt: pkg=python-pip state=present + when: app_before_buildout + +- name: install latest pip + become_user: root + easy_install: + name: pip + state: present + when: app_before_buildout + +- name: Clone project from sunflower repository (Git) + become: yes + become_user: "{{ odoo_user }}" + git: + clone: yes + force: yes + repo: "{{ sunflower_repo_url }}" + version: "{{ branch }}" + dest: "{{ odoo_workdir }}" + when: odoo_install_type != 'pip' and odoo_repo_type == 'git' and odoo_repo_url and sunflower_repo == True notify: Restart Odoo tags: - odoo_project -- name: Clone project repository (Git) +- name: Clone project from OCA repository (Git) become: yes become_user: "{{ odoo_user }}" git: repo={{ odoo_repo_url }} @@ -57,7 +130,7 @@ update={{ project_path.stat.exists == False and 'yes' or (odoo_repo_update and 'yes' or 'no') }} depth={{ odoo_repo_depth }} - when: odoo_install_type != 'pip' and odoo_repo_type == 'git' and odoo_repo_url + when: odoo_install_type != 'pip' and odoo_repo_type == 'git' and odoo_repo_url and sunflower_repo == False notify: Restart Odoo tags: - odoo_project @@ -90,7 +163,7 @@ - name: Install NPM packages import_tasks: install_npm.yml - when: (odoo_version | int) >= 9 + when: (odoo_version | int) >= 9 and app_after_buildout == True tags: - odoo - odoo_packages diff --git a/tasks/install_buildout.yml b/tasks/install_buildout.yml index 583651d..b016274 100644 --- a/tasks/install_buildout.yml +++ b/tasks/install_buildout.yml @@ -2,17 +2,16 @@ - name: Install build dependencies apt: pkg={{ item }} - state=installed + state=present update_cache={{ odoo_apt_update_cache }} cache_valid_time={{ odoo_apt_cache_valid_time }} with_items: "{{ odoo_buildout_build_dependencies }}" + when: app_before_buildout -- name: Install extra dependencies - apt: pkg={{ item }} - state=installed - update_cache={{ odoo_apt_update_cache }} - cache_valid_time={{ odoo_apt_cache_valid_time }} - with_items: "{{ odoo_buildout_extra_dependencies }}" +- name: Installing virtual enviroment using pip + pip: + name: virtualenv + when: env_type - name: Prepare the Python virtual environment become: yes @@ -20,10 +19,58 @@ shell: "{{ odoo_buildout_venv_cmd }}" args: creates: "{{ odoo_buildout_venv_path }}" + when: env_type - name: Copy the bootstrap.py script copy: src=bootstrap.py dest={{ odoo_buildout_bootstrap_path }} owner={{ odoo_user }} group={{ odoo_user }} force=no + when: not sunflower_repo + +- name: Remove local.cfg if exist + file: + path: "{{ odoo_workdir }}/local.cfg" + state: absent + when: sunflower_repo + +- name: Touch local.cfg + become_user: "{{ odoo_user }}" + file: + path: "{{ odoo_workdir }}/local.cfg" + state: touch + force: yes + when: sunflower_repo + +- name: Config local.cfg + become_user: "{{ odoo_user }}" + lineinfile: + dest: "{{ odoo_workdir }}/local.cfg" + line: "{{ item }}" + with_items: + - "[buildout]" + - "extends = {{ buildout_config_file }}" + - " " + - "[odoo]" + - "options.admin_passwd = {{ odoo_config_admin_passwd }}" + - "options.db_host = {{ odoo_config_db_host }}" + - "options.db_name = {{ odoo_config_db_name }}" + - "options.db_port = {{ odoo_config_db_port }}" + - "options.db_user = {{ odoo_config_db_user }}" + - "options.db_password = {{ odoo_config_db_passwd }}" + - "options.xmlrpc_port = {{ odoo_config_xmlrpc_port }}" + - "options.longpolling_port = {{ odoo_config_longpolling_port }}" + when: sunflower_repo + +- name: Copy odoo CFG files to container + copy: + src: "{{ item }}" + dest: /home/{{ odoo_user }}/odoo/ + force: yes + owner: "{{ odoo_user }}" + group: "{{ odoo_user }}" + mode: 0644 + with_fileglob: + - odoo_cfg_files/* + when: sunflower_repo - name: Install buildout (run the bootstrap.py script) become: yes @@ -31,9 +78,40 @@ command: "{{ odoo_buildout_bootstrap_cmd }}" args: creates: "{{ odoo_buildout_bin_path }}" + when: run_bootstrap + +- name: Stop Odoo + service: + name: "{{ odoo_service }}" + state: stop + when: run_buildout == True and run_bootstrap == False + failed_when: false + +- name: Installing setuptools python library using Ansible pip module + pip: + name: setuptools + version: 38.1.0 + when: run_buildout + +- name: "Download the pip requirements file for odoo {{ odoo_version }}" + become: yes + become_user: "{{ odoo_user }}" + get_url: url="https://raw.githubusercontent.com/odoo/odoo/{{ odoo_version }}/requirements.txt" dest="{{ odoo_workdir }}/requirements.txt" + when: run_buildout + +- name: "Install requirements for odoo {{ odoo_version }}" + become: yes + become_user: "{{ odoo_user }}" + pip: + requirements: "{{ odoo_workdir }}/requirements.txt" + state: present + notify: Restart Odoo + failed_when: false + when: run_buildout - name: Run buildout become: yes become_user: "{{ odoo_user }}" command: "{{ odoo_buildout_bin_path }} -c {{ odoo_buildout_config_path }}" changed_when: False + when: run_buildout diff --git a/tasks/install_npm.yml b/tasks/install_npm.yml index 40becdf..94e5928 100644 --- a/tasks/install_npm.yml +++ b/tasks/install_npm.yml @@ -5,20 +5,24 @@ url: "{{ item.url }}" state: "{{ item.state }}" with_items: "{{ odoo_nodejs_apt_keys | default([]) }}" + when: app_after_buildout - name: Configure NodeJS APT repository apt_repository: repo: "{{ item.repo }}" state: "{{ item.state }}" with_items: "{{ odoo_nodejs_apt_repositories | default([]) }}" + when: app_after_buildout - name: Install NodeJS apt: pkg="{{ odoo_nodejs_apt_package }}" - state=installed + state=present update_cache=yes + when: app_after_buildout - name: Install Odoo dependencies (npm) npm: name={{ item.name }} version={{ item.version }} global=yes with_items: "{{ odoo_npm_packages | default([]) }}" + when: app_after_buildout \ No newline at end of file diff --git a/tasks/install_pip.yml b/tasks/install_pip.yml index 574dfa0..705960e 100644 --- a/tasks/install_pip.yml +++ b/tasks/install_pip.yml @@ -6,17 +6,25 @@ - name: Install build dependencies apt: pkg={{ item }} - state=installed + state=present update_cache={{ odoo_apt_update_cache }} cache_valid_time={{ odoo_apt_cache_valid_time }} with_items: "{{ odoo_pip_build_dependencies }}" +- name: Install vertual enviroment + apt: pkg=python-virtualenv + state=installed + update_cache={{ odoo_apt_update_cache }} + cache_valid_time={{ odoo_apt_cache_valid_time }} + when: env_type + - name: Prepare the Python virtual environment become: yes become_user: "{{ odoo_user }}" shell: "{{ odoo_pip_venv_cmd }}" args: creates: "{{ odoo_pip_venv_path }}" + when: env_type - name: Download the pip requirements file become: yes diff --git a/tasks/install_ssh.yml b/tasks/install_ssh.yml index 905e228..5754c74 100644 --- a/tasks/install_ssh.yml +++ b/tasks/install_ssh.yml @@ -49,6 +49,9 @@ key: "{{ lookup('file', item) }}" with_fileglob: - "{{ odoo_user_sshkeys }}" - become: yes become_user: "{{ odoo_user }}" + + + + diff --git a/tasks/lxd_postgresql.yml b/tasks/lxd_postgresql.yml new file mode 100644 index 0000000..f11fd4e --- /dev/null +++ b/tasks/lxd_postgresql.yml @@ -0,0 +1,41 @@ +--- + +- name: Ensure libpq-dev is installed + apt: pkg=libpq-dev state=present + +- name: Ensure python-psycopg2 is installed + apt: pkg=python-psycopg2 state=present + +- name: Ensure postgresql is installed + apt: pkg=postgresql state=present + +- name: Create "{{ odoo_config_db_user }}" user into postgresql + become_user: postgres + postgresql_user: + name: "{{ odoo_config_db_user }}" + password: "{{ odoo_config_db_passwd }}" + role_attr_flags: "{{ odoo_config_db_user_righs }}" + when: new_postgresql_db + +- name: Ensure database is created + become_user: postgres + postgresql_db: name="{{ odoo_config_db_name }}" + encoding=UTF-8 + lc_collate=en_US.UTF-8 + lc_ctype=en_US.UTF-8 + state=present + owner="{{ odoo_config_db_user }}" + login_password="{{ odoo_config_db_passwd }}" + template=template0 + when: new_postgresql_db + +- name: Ensure user has access to the database + become_user: postgres + postgresql_privs: + database: "{{ odoo_config_db_name }}" + state: present + privs: ALL + type: database + roles: "{{ odoo_config_db_user }}" + grant_option: yes + when: new_postgresql_db diff --git a/tasks/main.yml b/tasks/main.yml index 9fb9c5f..21ac3d1 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,33 +1,60 @@ --- -- name: Set variables depending on the platform and the version of Odoo - include_vars: "{{ item }}" - with_first_found: - - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version | int}}_Odoo-{{ odoo_version | int }}.yml" - tags: - - always +- name: check "{{ lxd_container_name }}" if exist + shell: "lxc list |grep ' {{ lxd_container_name }} ' |cut -d'|' -f6 | awk '{print $1}'" + register: lxd_state + when: lxd_type == True -- import_tasks: install.yml - tags: - - odoo - - odoo_install +- debug: + msg: The {{ lxd_container_name }} container is exist + when: lxd_type == True and lxd_state.stdout == "PERSISTENT" -- import_tasks: wkhtmltox.yml - tags: - - odoo - - odoo_wkhtmltox +- meta: end_play + when: new_lxd_container == True and lxd_type == True and lxd_state.stdout == "PERSISTENT" + +- name: Be careful + debug: + msg: + - Warning Warning Warning Warning + - You chose 'new_lxd_container == False', That mean ansible will overwrite the exist container. + - If you are sure press 'c then Enter' to containeu. + - If you make it by mistake press 'q then Enter' then correct new_lxd_container variable to be 'True' and chose other lxd_container_name, then rerun ansible-playbook. + failed_when: True + ignore_errors: True + when: new_lxd_container == False and lxd_type == True and lxd_state.stdout == "PERSISTENT" + +- name: create "{{ lxd_container_name }}" + import_tasks: create_lxd_container.yml + when: lxd_type == True and lxd_container_name != "localhost" and lxd_step == True -- import_tasks: reportlab.yml + + +- name: Work into LXD container + delegate_to: "{{ lxd_container_name }}" + import_tasks: work_into_lxd_container.yml tags: - - odoo - - odoo_reportlab + - lxd_container + when: lxd_type -- import_tasks: postgresql.yml +- name: Create and config LXD postgresql database + import_tasks: lxd_postgresql.yml + when: lxd_type == False and postgresql_step == True + +- name: Direct intallation + import_tasks: direct_installation.yml tags: - - odoo - - odoo_postgresql + - direct_installation + when: lxd_type == False -- import_tasks: service.yml +- name: Config LXD container in nginx + import_tasks: config_nginx_proxy.yml tags: - - odoo - - odoo_service + - nginx + - lxd_container + - lxd + when: nginx_step + +- debug: + msg: + - For more information please read our toturial + - https://github.com/sunflowerit/ansible-odoo diff --git a/tasks/reportlab.yml b/tasks/reportlab.yml index 19d5248..21d0e71 100644 --- a/tasks/reportlab.yml +++ b/tasks/reportlab.yml @@ -8,7 +8,7 @@ file: path="/home/{{ odoo_user }}/fonts" state=directory - name: Install unzip - apt: name=unzip state=installed + apt: name=unzip state=present - name: Unzip the ReportLab fonts unarchive: src="/opt/pfbfer.zip" diff --git a/tasks/service.yml b/tasks/service.yml index 87e369e..3a6eaaa 100644 --- a/tasks/service.yml +++ b/tasks/service.yml @@ -1,5 +1,71 @@ --- +- block: + - name: Generate Odoo init script (standard) + template: src=odoo-{{ odoo_version }}.init dest=/etc/init.d/{{ odoo_service }} + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr != 'systemd' + notify: Restart LXD-Odoo + + - name: Generate systemd Odoo service (standard) + template: + src=odoo-standard.service + dest=/etc/systemd/system/{{ odoo_service }}.service + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr == 'systemd' + notify: + - Reload LXD-Systemd + - Restart LXD-Odoo + when: odoo_install_type == 'standard' and lxd_type == True + +- block: + - name: Generate Odoo init script (buildout) + template: src=odoo-buildout.init dest=/etc/init.d/{{ odoo_service }} + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr != 'systemd' + notify: Restart LXD-Odoo + + - name: Generate systemd Odoo service (buildout) + template: + src=odoo-buildout.service + dest=/etc/systemd/system/{{ odoo_service }}.service + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr == 'systemd' + notify: + - Reload LXD-Systemd + - Restart LXD-Odoo + when: odoo_install_type == 'buildout' and lxd_type == True + +- block: + - name: Generate Odoo init script (pip) + template: src=odoo-pip.init dest=/etc/init.d/{{ odoo_service }} + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr != 'systemd' + notify: Restart LXD-Odoo + + - name: Generate systemd Odoo service (pip) + template: + src=odoo-pip.service + dest=/etc/systemd/system/{{ odoo_service }}.service + owner=root group=root mode=0755 + force=yes + backup=yes + when: ansible_service_mgr == 'systemd' + notify: + - Reload LXD-Systemd + - Restart LXD-Odoo + when: odoo_install_type == 'pip' and lxd_type == True + - block: - name: Generate Odoo init script (standard) template: src=odoo-{{ odoo_version }}.init dest=/etc/init.d/{{ odoo_service }} @@ -20,7 +86,7 @@ notify: - Reload Systemd - Restart Odoo - when: odoo_install_type == 'standard' + when: odoo_install_type == 'standard' and lxd_type == False - block: - name: Generate Odoo init script (buildout) @@ -42,7 +108,7 @@ notify: - Reload Systemd - Restart Odoo - when: odoo_install_type == 'buildout' + when: odoo_install_type == 'buildout' and lxd_type == False - block: - name: Generate Odoo init script (pip) @@ -64,7 +130,7 @@ notify: - Reload Systemd - Restart Odoo - when: odoo_install_type == 'pip' + when: odoo_install_type == 'pip' and lxd_type == False - name: Enable Odoo service service: name={{ odoo_service }} enabled=yes state=started @@ -73,3 +139,5 @@ - name: Disable Odoo service service: name={{ odoo_service }} enabled=no state=stopped when: odoo_init == False + + diff --git a/tasks/wkhtmltox.yml b/tasks/wkhtmltox.yml index 3207417..e19a1cb 100644 --- a/tasks/wkhtmltox.yml +++ b/tasks/wkhtmltox.yml @@ -9,6 +9,7 @@ with_items: "{{ odoo_wkhtmltox_urls }}" ignore_errors: True when: odoo_wkhtmltox_version is defined and odoo_wkhtmltox_version != False + failed_when: false # Use to detect that the package was downloaded. # We can not register the result of the previous task to check this as Ansible diff --git a/tasks/work_into_lxd_container.yml b/tasks/work_into_lxd_container.yml new file mode 100644 index 0000000..28fe048 --- /dev/null +++ b/tasks/work_into_lxd_container.yml @@ -0,0 +1,54 @@ +--- + +- name: config LXD container + import_tasks: config_lxd_container.yml + tags: + - lxd_container + - lxd + when: lxd_type == True and lxd_step == True and lxd_container_name != "localhost" + +- name: Create and config LXD postgresql database + import_tasks: lxd_postgresql.yml + when: postgresql_step + +- name: Set variables depending on the platform and the version of Odoo + include_vars: "{{ item }}" + with_first_found: + - "../vars/{{ ansible_distribution }}-{{ ansible_distribution_major_version | int}}_Odoo-{{ odoo_version | int }}.yml" + tags: + - always + when: buildout_step + +- name: Set variables to work without virtual environment + set_fact: odoo_buildout_venv_path="/usr" odoo_pip_venv_path="/usr" + when: env_type == False and buildout_step == True + +- name: Set variables to config buildout from local.cfg + set_fact: odoo_buildout_config_path="{{ odoo_workdir }}/local.cfg" + when: sunflower_repo == True and buildout_step == True + +- import_tasks: install.yml + tags: + - odoo + - odoo_install + when: buildout_step + +- import_tasks: wkhtmltox.yml + tags: + - odoo + - odoo_wkhtmltox + when: buildout_step == True and app_after_buildout == True + +- import_tasks: reportlab.yml + tags: + - odoo + - odoo_reportlab + when: buildout_step == True and app_after_buildout == True + +- import_tasks: service.yml + tags: + - odoo + - odoo_service + when: buildout_step + + diff --git a/templates/odoo-11.0.init b/templates/odoo-11.0.init deleted file mode 120000 index 5cb1712..0000000 --- a/templates/odoo-11.0.init +++ /dev/null @@ -1 +0,0 @@ -odoo-10.0.init \ No newline at end of file diff --git a/templates/odoo-11.0.init b/templates/odoo-11.0.init new file mode 100644 index 0000000..1b9a7a7 --- /dev/null +++ b/templates/odoo-11.0.init @@ -0,0 +1,81 @@ +#!/bin/bash +### BEGIN INIT INFO +# Provides: {{ odoo_service }} +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: $network +# Should-Stop: $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Start odoo daemon at boot time +# Description: Enable service provided by daemon. +### END INIT INFO +## more info: http://wiki.debian.org/LSBInitScripts + +. /lib/lsb/init-functions + +PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin +WORKDIR={{ odoo_workdir }} +DAEMON={{ odoo_rootdir }}/odoo-bin +NAME={{ odoo_service }} +DESC={{ odoo_service }} +CONFIG={{ odoo_config_file }} +LOGFILE={{ odoo_logfile }} +PIDFILE=/var/run/${NAME}.pid +USER={{ odoo_user }} +export LOGNAME=$USER +{% if odoo_init_env %} +# Custom environment variables +{% for name, value in odoo_init_env.iteritems() %} +export {{ name }}={{ value }} +{% endfor %} +{% endif %} + +test -x $DAEMON || exit 0 +set -e + +function _start() { + start-stop-daemon --chdir=${WORKDIR} --start --quiet --pidfile $PIDFILE --chuid $USER:$USER --background --make-pidfile --exec $DAEMON -- --config $CONFIG --logfile $LOGFILE +} + +function _stop() { + start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --retry 3 + rm -f $PIDFILE +} + +function _status() { + start-stop-daemon --status --quiet --pidfile $PIDFILE + return $? +} + + +case "$1" in + start) + echo -n "Starting $DESC: " + _start + echo "ok" + ;; + stop) + echo -n "Stopping $DESC: " + _stop + echo "ok" + ;; + restart|force-reload) + echo -n "Restarting $DESC: " + _stop + sleep 1 + _start + echo "ok" + ;; + status) + echo -n "Status of $DESC: " + _status && echo "running" || echo "stopped" + ;; + *) + N=/etc/init.d/$NAME + echo "Usage: $N {start|stop|restart|force-reload|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/vars/Ubuntu-16_Odoo-10.yml b/vars/Ubuntu-16_Odoo-10.yml index 8265785..2b50904 100644 --- a/vars/Ubuntu-16_Odoo-10.yml +++ b/vars/Ubuntu-16_Odoo-10.yml @@ -76,7 +76,6 @@ odoo_pip_build_dependencies: - libssl-dev odoo_buildout_build_dependencies: - - virtualenv - build-essential - python-dev - libxml2-dev @@ -90,6 +89,7 @@ odoo_buildout_build_dependencies: - libfreetype6-dev - liblcms2-dev - libwebp-dev + - libffi-dev odoo_wkhtmltox_depends: - fontconfig diff --git a/vars/Ubuntu-16_Odoo-11.yml b/vars/Ubuntu-16_Odoo-11.yml index 890ceec..4a77164 100644 --- a/vars/Ubuntu-16_Odoo-11.yml +++ b/vars/Ubuntu-16_Odoo-11.yml @@ -78,9 +78,10 @@ odoo_pip_build_dependencies: - liblcms2-dev - libwebp-dev - libssl-dev + - libffi-dev + - node-less odoo_buildout_build_dependencies: - - virtualenv - build-essential - python3-dev - libxml2-dev diff --git a/vars/Ubuntu-16_Odoo-8.yml b/vars/Ubuntu-16_Odoo-8.yml index f667248..6920256 100644 --- a/vars/Ubuntu-16_Odoo-8.yml +++ b/vars/Ubuntu-16_Odoo-8.yml @@ -44,7 +44,7 @@ odoo_pip_dependencies: - setuptools-odoo==2.0.2.post1 odoo_pip_build_dependencies: - - python-virtualenv + - virtualenv - build-essential - python-dev - libxml2-dev @@ -61,7 +61,6 @@ odoo_pip_build_dependencies: - libssl-dev odoo_buildout_build_dependencies: - - virtualenv - build-essential - python-dev - libxml2-dev diff --git a/vars/Ubuntu-16_Odoo-9.yml b/vars/Ubuntu-16_Odoo-9.yml index 3aaed1c..8634aed 100644 --- a/vars/Ubuntu-16_Odoo-9.yml +++ b/vars/Ubuntu-16_Odoo-9.yml @@ -71,7 +71,6 @@ odoo_pip_build_dependencies: - libssl-dev odoo_buildout_build_dependencies: - - virtualenv - build-essential - python-dev - libxml2-dev @@ -85,6 +84,7 @@ odoo_buildout_build_dependencies: - libfreetype6-dev - liblcms2-dev - libwebp-dev + - libffi-dev odoo_wkhtmltox_version: 0.12.1 diff --git a/vars/main.yml b/vars/main.yml index ef46a39..0e1e48c 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -40,3 +40,8 @@ odoo_nodejs_apt_keys: # SSH odoo_ssh_keyscan_cmd: "ssh-keyscan -H -T 10" + + + + + From b7b8d10307b27c8992b6e369b819f0c81b591086 Mon Sep 17 00:00:00 2001 From: Hayyan-Ebrahem <29663991+Hayyan-Ebrahem@users.noreply.github.com> Date: Wed, 30 May 2018 17:13:43 +0200 Subject: [PATCH 2/2] Update README_FOR_SUNFLOWER_TEAM.md --- README_FOR_SUNFLOWER_TEAM.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README_FOR_SUNFLOWER_TEAM.md b/README_FOR_SUNFLOWER_TEAM.md index 2018bf3..68b7606 100644 --- a/README_FOR_SUNFLOWER_TEAM.md +++ b/README_FOR_SUNFLOWER_TEAM.md @@ -39,11 +39,11 @@ this folder include variables preference allow tasks to choose between it occurr ## Example (Playbook) -to use this ansible roles we must copy /etc/ansible folder to home directory then edit ansible.cfg file clear all lins in it and put this line: +to use this ansible roles we must copy /etc/ansible folder to home directory then edit ansible.cfg file clear all lines in it and put this line: [defaults] inventory = hosts enable_task_debugger = True -then edit hosts file clear all lins in it and put this line: +then edit hosts file, clear all lines and put this line: localhost then git clone our repository in roles folder: @@ -61,7 +61,7 @@ then touch default.yml in ansible works directory and put this lines into it: then run this command ansible-playbook -K default.yml -by this command ansible run in default variables so the roles will do that steps: +by this command ansible runs in default variables so the roles will do the following steps: 1- create LXD container: 'lxdcontainer' and put "lxdcontainer ansible_connection=lxd" line in ansible inventory hosts file 'hosts' to make 'lxdcontainer' available in ansible enviroment @@ -152,9 +152,9 @@ by this command ansible run in default variables so the roles will do that steps 22- try to reload nginx by this command: nginx -t && nginx -s reload -now we can tchange ansible-playbook behavier by put some variable value in blaybook.yml +now we can change ansible-playbook behavior by assigning to some variables in blaybook.yml for example -to make a new container and giv it simpleodoo10 and install odoo 10.0 inside this container from 10.0-custom-standard bransh and config nginx to make this container available in simpleodoo10.sunflowerodoo.nl we touch odoo_10_default.yml in ansible works directory and edit it to be: +to make a new container and give it simpleodoo10 name and install odoo 10.0 inside this container from 10.0-custom-standard bransh and to config nginx to make this container available in simpleodoo10.sunflowerodoo.nl we touch odoo_10_default.yml in ansible working directory and edit it to be: ```yaml - name: Odoo hosts: localhost