diff --git a/configure_otree.yml b/configure_otree.yml index d7396dc2224cef5111367be5919ab00cf9ec9e05..addc912b849d39300affa6efdd84636eb875c3a8 100644 --- a/configure_otree.yml +++ b/configure_otree.yml @@ -7,13 +7,13 @@ - name: remove old projects file: state: absent - path: "/home/{{ item.key }}/otree/" + path: "{{ home_path }}/{{ item.key }}/otree/" with_dict: "{{ otree_users }}" when: item.value.override - name: add project folder again file: - path: "/home/{{ item.key }}/otree/" + path: "{{ home_path }}/{{ item.key }}/otree/" state: directory owner: "{{ item.key }}" group: "{{ item.key }}" @@ -24,14 +24,14 @@ - name: copy over ssh key files synchronize: src: "keys/{{ item.key }}/" - dest: "/home/{{ item.key }}/.ssh/" + dest: "{{ home_path }}/{{ item.key }}/.ssh/" delete: yes with_dict: "{{ otree_users }}" when: item.value.override and item.value.app_repo is defined - name: set owner and group permissions restricted for key files file: - path: "/home/{{ item.key }}/.ssh/" + path: "{{ home_path }}/{{ item.key }}/.ssh/" state: directory owner: "{{ item.key }}" group: "{{ item.key }}" @@ -42,7 +42,7 @@ - name: set owner and group permissions for folder file: - path: "/home/{{ item.key }}/.ssh/" + path: "{{ home_path }}/{{ item.key }}/.ssh/" state: directory owner: "{{ item.key }}" group: "{{ item.key }}" @@ -53,10 +53,10 @@ - name: clone projects accordingly git: repo: "{{ item.value.app_repo }}" - dest: "/home/{{ item.key }}/otree/" + dest: "{{ home_path }}/{{ item.key }}/otree/" accept_hostkey: yes recursive: yes - key_file: "/home/{{ item.key }}/.ssh/id" + key_file: "{{ home_path }}/{{ item.key }}/.ssh/id" become: yes become_user: "{{ item.key }}" with_dict: "{{ otree_users }}" @@ -65,14 +65,14 @@ - name: copy over project files synchronize: src: "files/{{ item.key }}/" - dest: "/home/{{ item.key }}/otree/" + dest: "{{ home_path }}/{{ item.key }}/otree/" delete: yes with_dict: "{{ otree_users }}" when: item.value.override and item.value.app_repo is not defined - name: set owner and group permissions file: - path: "/home/{{ item.key }}/otree/" + path: "{{ home_path }}/{{ item.key }}/otree/" state: directory owner: "{{ item.key }}" group: "{{ item.key }}" @@ -84,7 +84,7 @@ - name: remove old venv file: state: absent - path: "/home/{{ item.key }}/.venv_otree/" + path: "{{ home_path }}/{{ item.key }}/.venv_otree/" become: yes become_user: "{{ item.key }}" with_dict: "{{ otree_users }}" @@ -96,7 +96,7 @@ pip: name: psycopg2 state: present - virtualenv: "/home/{{ item.key }}/.venv_otree" + virtualenv: "{{ home_path }}/{{ item.key }}/.venv_otree" virtualenv_command: "{{ item.value.python_binary_path }} -m venv" become: yes become_user: "{{ item.key }}" @@ -108,7 +108,7 @@ # name: otree # state: present # extra_args: "{{ '--pre' if item.value.pre_release else '' }}" - # virtualenv: "/home/{{ item.key }}/.venv_otree" + # virtualenv: "{{ home_path }}/{{ item.key }}/.venv_otree" # virtualenv_command: "/usr/bin/python{{ '3.7' if item.value.pre_release else '3'}} -m venv" # become: yes # become_user: "{{ item.key }}" @@ -118,20 +118,20 @@ - name: install requirements if exists pip: state: present - requirements: "/home/{{ item.key }}/otree/requirements.txt" - virtualenv: "/home/{{ item.key }}/.venv_otree" + requirements: "{{ home_path }}/{{ item.key }}/otree/requirements.txt" + virtualenv: "{{ home_path }}/{{ item.key }}/.venv_otree" virtualenv_command: "{{ item.value.python_binary_path }} -m venv" become: yes become_user: "{{ item.key }}" with_dict: "{{ otree_users }}" when: item.value.override - ignore_errors: yes + #ignore_errors: yes # reset and prepare otree - name: reset otree database - shell: "source /home/{{ item.key }}/.venv_otree/bin/activate && otree resetdb --noinput" + shell: "source {{ home_path }}/{{ item.key }}/.venv_otree/bin/activate && otree resetdb --noinput" args: - chdir: "/home/{{ item.key }}/otree/" + chdir: "{{ home_path }}/{{ item.key }}/otree/" executable: /bin/bash environment: DATABASE_URL: "{{ item.value.database }}" diff --git a/group_vars/otree_servers.yml.example b/group_vars/otree_servers.yml.example index 11b173514067c07593f94607dc012da9cc5b7ad8..1c9db4dc812f2cc98a3ce2e14a69645ac7635e82 100644 --- a/group_vars/otree_servers.yml.example +++ b/group_vars/otree_servers.yml.example @@ -2,6 +2,8 @@ ansible_user: "mylinuxuser" ansible_connection: "local" +home_path: "/home" + nginx_config_path: "/etc/nginx" nginx_sites_available: "{{ nginx_config_path }}/sites-available" nginx_sites_enabled: "{{ nginx_config_path }}/sites-enabled" @@ -19,8 +21,8 @@ otree_users: # should a existing otree environment be overriden redis: "redis://localhost:6379/1" # redis queue. Note don't use a slot twice, there are 16 slots available (0-15) - database: "sqlite:////home/otree1/db.sqlite3" - # which database should be used. Examples: "postgres://USER:PASSWORD@HOST:PORT/NAME" or "sqlite:////home/user/db.sqlite3" + database: "sqlite:///{{ home_path }}/otree1/db.sqlite3" + # which database should be used. Examples: "postgres://USER:PASSWORD@HOST:PORT/NAME" or "sqlite:///{{ home_path }}/user/db.sqlite3" admin_pw: "mysecretpw1" # otree admin password auth_level: "STUDY" @@ -41,7 +43,7 @@ otree_users: # for ssh: git@domain:project-group/project.git pre_release: yes redis: "redis://localhost:6379/2" - database: "sqlite:////home/otree2/db.sqlite3" + database: "sqlite:///{{ home_path }/otree2/db.sqlite3" admin_pw: "mysecretpw2" auth_level: "DEMO" secret_key: "sdfunlidsgjndrsgf" diff --git a/site.yml b/site.yml index 2761bda74b03761cbc3dae213e22d2be5b84ccc9..7f37b058f483dee63499ba3bef3e4e66d5cd54eb 100644 --- a/site.yml +++ b/site.yml @@ -42,6 +42,8 @@ name: "{{ item.key }}" shell: /bin/bash groups: ["{{ otree_group_name }}"] + home: "{{ home_path }}/{{ item.key }}" + move_home: yes state: present with_dict: "{{ otree_users }}" diff --git a/templates/supervisor_otree.conf.j2 b/templates/supervisor_otree.conf.j2 index 888cc906676bd5ebd0ad9abe36c4049ad02521c0..127e7086abd409cfa2386cc58f3ee606aa635a01 100644 --- a/templates/supervisor_otree.conf.j2 +++ b/templates/supervisor_otree.conf.j2 @@ -1,6 +1,6 @@ [program:{{ item.key }}] -directory=/home/{{ item.key }}/otree/ -command=/bin/bash -c "source /home/{{ item.key }}/.venv_otree/bin/activate && otree runprodserver" +directory={{ home_path }}/{{ item.key }}/otree/ +command=/bin/bash -c "source {{ home_path }}/{{ item.key }}/.venv_otree/bin/activate && otree runprodserver" environment=DATABASE_URL="{{ item.value.database }}",REDIS_URL="{{ item.value.redis }}",OTREE_ADMIN_PASSWORD="{{ item.value.admin_pw }}",OTREE_AUTH_LEVEL="{{ item.value.auth_level }}",OTREE_SECRET_KEY="{{ item.value.secret_key }}",OTREE_PRODUCTION="{{ item.value.production }}",PORT={{ item.value.port }} autostart=true autorestart=true @@ -19,4 +19,4 @@ stderr_logfile=/dev/null ; stderr_logfile=/var/log/supervisor/{{ item.key }}.err.log ; stderr_logfile_maxbytes=1MB ; stderr_logfile_backups=10 -; stderr_events_enabled=false \ No newline at end of file +; stderr_events_enabled=false