diff --git a/roles/deploy_code/defaults/main.yml b/roles/deploy_code/defaults/main.yml index 7b68c3a7..b8220475 100644 --- a/roles/deploy_code/defaults/main.yml +++ b/roles/deploy_code/defaults/main.yml @@ -1,5 +1,13 @@ --- +# Required for NGINX config in feature branching. +_ce_provision_data_dir: /home/deploy/ce-deploy/data + deploy_code: + # Feature branching config. + feature_branch: + enabled: false + # NGINX domains to build, see ce-provision for docs: https://github.com/codeenigma/ce-provision/blob/2.x/roles/debian/nginx/defaults/main.yml#L133 + domains: [] # Specify any additional symlink to create, with src (target) and dest (link). # src: can be either absolute or relative to the dest (eg. '/var/my_data', '/home/deploy/simplesaml', '../../../myconfig') # dest: can only be relative to the root of your repository (eg. 'www/themes/myassets', 'var/cache') diff --git a/roles/deploy_code/tasks/deploy.yml b/roles/deploy_code/tasks/deploy.yml index 0d15425c..95e3a310 100644 --- a/roles/deploy_code/tasks/deploy.yml +++ b/roles/deploy_code/tasks/deploy.yml @@ -38,3 +38,68 @@ loop_var: link when: - deploy_code.symlinks | length + +# Additional vhost handling for feature branch builds. + +# Fetch the NGINX domain handling tasks from ce-provision. +- name: Ensure the nginx directory exists. + ansible.builtin.file: + path: "{{ _ce_deploy_base_dir }}/roles/nginx/{{ item }}" + state: directory + mode: '0755' + delegate_to: localhost + with_items: + - tasks + - defaults + - templates + when: deploy_code.feature_branch.enabled + +- name: Fetch the nginx role files from ce-provision. + when: deploy_code.feature_branch.enabled + delegate_to: localhost + block: + - name: Fetch domain.yml. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/tasks/domain.yml + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + + - name: Fetch defaults. + ansible.builtin.get_url: + url: https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/defaults/main.yml + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/defaults/main.yml" + + - name: Fetch templates. + ansible.builtin.get_url: + url: "https://raw.githubusercontent.com/codeenigma/ce-provision/2.x/roles/debian/nginx/templates/{{ item }}" + dest: "{{ _ce_deploy_base_dir }}/roles/nginx/templates/{{ item }}" + with_items: + - vhosts.j2 + - cloudwatch-vhost.json.j2 + +- name: Create vhost. + when: + - deploy_code.feature_branch.domains is defined + - deploy_code.feature_branch.domains | length > 0 + - deploy_code.feature_branch.enabled + become: true + block: + - name: Generate domain specific configuration. + ansible.builtin.include_tasks: "{{ _ce_deploy_base_dir }}/roles/nginx/tasks/domain.yml" + with_items: "{{ deploy_code.feature_branch.domains }}" + loop_control: + loop_var: domain + + - name: Test NGINX configuration. + ansible.builtin.command: nginx -t + register: _nginx_test_result + failed_when: false + + - name: Display NGINX test result. + ansible.builtin.debug: + msg: "{{ _nginx_test_result.stderr }}" + + - name: Ensure NGINX is reloaded. + ansible.builtin.service: + name: nginx + state: reloaded + when: _nginx_test_result.rc == 0