diff --git a/ops/ansible/inventories/legislation.demo.openfisca.org.yml b/ops/ansible/inventories/legislation.demo.openfisca.org.yml new file mode 100644 index 00000000..3d036da2 --- /dev/null +++ b/ops/ansible/inventories/legislation.demo.openfisca.org.yml @@ -0,0 +1,28 @@ +all: + hosts: + vps-60ea1664.openfisca.org: + ansible_user: root + + api_url: https://api.demo.openfisca.org/latest + app_port: 8101 + + ui_strings: | + { + "en": + { "countryName": "Demo", "search_placeholder": "salary, disposable income" }, + "fr": + { "countryName": "Demo", "search_placeholder": "salary, disposable income" } + } + + matomo_url: https://stats.data.gouv.fr/piwik.php + matomo_site_id: 4 + + source_dir: legislation-explorer-demo # relative to the home directory + systemd_service_file_name: legislation-explorer-demo.service + + # Reverse proxy + + host_name: legislation.demo.openfisca.org + + letsencrypt_email: contact@openfisca.org + letsencrypt_environment: production diff --git a/ops/ansible/inventories/legislation.fr.openfisca.org.yml b/ops/ansible/inventories/legislation.fr.openfisca.org.yml index dad62c77..02f81f64 100644 --- a/ops/ansible/inventories/legislation.fr.openfisca.org.yml +++ b/ops/ansible/inventories/legislation.fr.openfisca.org.yml @@ -3,13 +3,26 @@ all: vps-60ea1664.openfisca.org: ansible_user: root - host_name: legislation.fr.openfisca.org + api_url: https://api.fr.openfisca.org/latest app_port: 8100 - api_url: https://api.fr.openfisca.org/latest - - letsencrypt_email: contact@openfisca.org - letsencrypt_environment: production + ui_strings: | + { + "en": + { "countryName": "France", "search_placeholder": "smic, salaire net" }, + "fr": + { "countryName": "France", "search_placeholder": "smic, salaire net" } + } matomo_url: https://stats.data.gouv.fr/piwik.php matomo_site_id: 4 + + source_dir: legislation-explorer-fr # relative to the home directory + systemd_service_file_name: legislation-explorer-fr.service + + # Reverse proxy + + host_name: legislation.fr.openfisca.org + + letsencrypt_email: contact@openfisca.org + letsencrypt_environment: production diff --git a/ops/ansible/roles/legislation_explorer/defaults/main.yml b/ops/ansible/roles/legislation_explorer/defaults/main.yml index 190c5dee..f23d5eae 100644 --- a/ops/ansible/roles/legislation_explorer/defaults/main.yml +++ b/ops/ansible/roles/legislation_explorer/defaults/main.yml @@ -1,20 +1,22 @@ api_url: http://localhost:8000 app_host: 127.0.0.1 app_port: 8001 -base_path: / changelog_url: https://github.com/openfisca/openfisca-france/blob/master/CHANGELOG.md -host_name: localhost ui_strings: | { "en": - { "countryName": "France", "search_placeholder": "smic, salaire net" }, + { "countryName": "Demo", "search_placeholder": "salary, disposable income" }, "fr": - { "countryName": "France", "search_placeholder": "smic, salaire net" } + { "countryName": "Demo", "search_placeholder": "salary, disposable income" } } repo_url: https://github.com/openfisca/legislation-explorer.git branch: master +# Reverse proxy +host_name: localhost +base_path: / + # Optional: SSL certificate # An SSL certificate is issued from Let's Encrypt if `letsencrypt_email` is defined. letsencrypt_email: null @@ -26,7 +28,7 @@ matomo_url: null matomo_site_id: null # Fully managed by Ansible, you should not need to edit this unless you have a naming collision -source_dir: "/home/{{ unix_user_name }}/legislation-explorer" -systemd_service_file: /etc/systemd/system/legislation-explorer.service +source_dir: legislation-explorer # relative to the home directory +systemd_service_file_name: legislation-explorer.service unix_group_name: openfisca unix_user_name: legislation-explorer diff --git a/ops/ansible/roles/legislation_explorer/tasks/main.yml b/ops/ansible/roles/legislation_explorer/tasks/main.yml index b10b48ae..633c1647 100644 --- a/ops/ansible/roles/legislation_explorer/tasks/main.yml +++ b/ops/ansible/roles/legislation_explorer/tasks/main.yml @@ -30,45 +30,49 @@ shell: /bin/bash register: unix_user +- name: Define the path of the source directory + ansible.builtin.set_fact: + source_dir_path: "{{ unix_user.home }}/{{ source_dir }}" + - name: Clone the Git repository of Legislation Explorer ansible.builtin.git: # Discard any local changes otherwise the task will fail. # Sometimes the package-lock.json is modified due to changes in its structure. force: yes repo: "{{ repo_url }}" - dest: "{{ source_dir }}" + dest: "{{ source_dir_path }}" version: "{{ branch }}" become_user: "{{ unix_user_name }}" - name: Install npm dependencies ansible.builtin.npm: - path: "{{ source_dir }}" + path: "{{ source_dir_path }}" production: yes state: present - name: Copy the environment file for Legislation Explorer ansible.builtin.template: src: systemd/legislation-explorer.env.j2 - dest: "{{ source_dir }}/.env" + dest: "{{ source_dir_path }}/.env" - name: Build the application ansible.builtin.command: npm run build args: - chdir: "{{ source_dir }}" + chdir: "{{ source_dir_path }}" - name: Set up the systemd service block: - name: Copy the systemd service file ansible.builtin.template: src: systemd/legislation-explorer.service.j2 - dest: "{{ systemd_service_file }}" + dest: "/etc/systemd/system/{{ systemd_service_file_name }}" - name: Enable and start the systemd service ansible.builtin.systemd: daemon_reload: yes enabled: yes state: restarted - name: legislation-explorer + name: "{{ systemd_service_file_name }}" - name: Check that Legislation Explorer is actually started ansible.builtin.uri: @@ -105,16 +109,10 @@ state: present update_cache: no - - name: Handle staging environment + - name: Use Let's Encrypt staging environment when: letsencrypt_environment == "staging" - block: - - name: Display message when staging environment is used - ansible.builtin.debug: - msg: Let's Encrypt staging environment will be used - - - name: Define certbot --staging option - ansible.builtin.set_fact: - certbot_staging_option: "--staging" + ansible.builtin.set_fact: + certbot_staging_option: "--staging" - name: Reinstall or renew an SSL certificate from Let's Encrypt using the certbot client ansible.builtin.command: > diff --git a/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.service.j2 b/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.service.j2 index 67004995..80d695ad 100644 --- a/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.service.j2 +++ b/ops/ansible/roles/legislation_explorer/templates/systemd/legislation-explorer.service.j2 @@ -3,7 +3,7 @@ Description=OpenFisca Legislation Explorer [Service] ExecStart=/usr/bin/npm start -WorkingDirectory={{ source_dir | quote }} +WorkingDirectory={{ source_dir_path | quote }} User={{ unix_user_name }} Group={{ unix_group_name }}