|
1 |
| -- name: Install prerequisite packages |
2 |
| - ansible.builtin.include_tasks: "{{ ansible_os_family }}.yml" |
| 1 | +- name: Check required variables |
| 2 | + ansible.builtin.fail: msg="Variable '{{ item }}' is not defined" |
| 3 | + when: item not in vars |
| 4 | + loop: |
| 5 | + - certificate |
| 6 | + - certificate_key |
| 7 | + - server_name |
| 8 | + |
| 9 | +- name: Install upstream packages |
| 10 | + when: nginx_upstream | bool |
| 11 | + ansible.builtin.include_tasks: "{{ ansible_os_family }}-upstream.yml" |
| 12 | + |
| 13 | +- name: Install packages from distribution server |
| 14 | + when: not nginx_upstream | bool |
| 15 | + ansible.builtin.include_tasks: "{{ ansible_os_family }}-ownstream.yml" |
3 | 16 |
|
4 | 17 | - name: Install nginx
|
5 | 18 | become: true
|
|
9 | 22 | register: install_nginx
|
10 | 23 | retries: 5
|
11 | 24 | delay: 60
|
12 |
| - until: install_nginx is succeeded |
| 25 | + until: install_nginx is success |
13 | 26 |
|
14 |
| -- name: Copy nginx.conf file |
| 27 | +- name: Configure main nginx conf file. |
15 | 28 | become: true
|
16 | 29 | ansible.builtin.template:
|
17 | 30 | src: "{{ nginx_conf_template }}"
|
|
20 | 33 | group: root
|
21 | 34 | mode: '0755'
|
22 | 35 |
|
23 |
| -- name: Generate artifactory.conf |
| 36 | +- name: Configure redirect nginx conf |
| 37 | + when: |
| 38 | + - artifactory_nginx_ssl_enabled is defined |
| 39 | + - artifactory_nginx_ssl_enabled | bool |
| 40 | + become: true |
| 41 | + ansible.builtin.copy: |
| 42 | + src: redirect_http_to_https.conf |
| 43 | + dest: /etc/nginx/conf.d/redirect_http_to_https.conf |
| 44 | + owner: root |
| 45 | + group: root |
| 46 | + mode: '0755' |
| 47 | + when: redirect_http_to_https_enabled | bool |
| 48 | + notify: Restart nginx |
| 49 | + |
| 50 | +- name: Configure the artifactory nginx conf |
24 | 51 | become: true
|
25 | 52 | ansible.builtin.template:
|
26 | 53 | src: "{{ artifactory_conf_template }}"
|
|
30 | 57 | mode: '0755'
|
31 | 58 | notify: Restart nginx
|
32 | 59 |
|
| 60 | +- name: Configure SSL |
| 61 | + when: |
| 62 | + - artifactory_nginx_ssl_enabled is defined |
| 63 | + - artifactory_nginx_ssl_enabled | bool |
| 64 | + - ssl_certificate_install | bool |
| 65 | + block: |
| 66 | + - name: Create directory |
| 67 | + become: true |
| 68 | + ansible.builtin.file: |
| 69 | + path: "/var/opt/jfrog/nginx/ssl" |
| 70 | + state: directory |
| 71 | + mode: '0755' |
| 72 | + |
| 73 | + - name: Ensure ssl_certificate_path exists |
| 74 | + become: true |
| 75 | + ansible.builtin.file: |
| 76 | + path: "{{ ssl_certificate_path }}" |
| 77 | + state: directory |
| 78 | + mode: '0755' |
| 79 | + |
| 80 | + - name: Ensure ssl_certificate_key_path exists |
| 81 | + become: true |
| 82 | + ansible.builtin.file: |
| 83 | + path: "{{ ssl_certificate_key_path }}" |
| 84 | + state: directory |
| 85 | + mode: '0700' |
| 86 | + |
| 87 | + - name: Configure certificate |
| 88 | + become: true |
| 89 | + ansible.builtin.template: |
| 90 | + src: certificate.pem.j2 |
| 91 | + dest: "{{ ssl_certificate_path }}/{{ ssl_certificate }}" |
| 92 | + mode: '0644' |
| 93 | + notify: Restart nginx |
| 94 | + no_log: true |
| 95 | + |
| 96 | + - name: Configure key |
| 97 | + become: true |
| 98 | + ansible.builtin.template: |
| 99 | + src: certificate.key.j2 |
| 100 | + dest: "{{ ssl_certificate_key_path }}/{{ ssl_certificate_key }}" |
| 101 | + mode: '0600' |
| 102 | + notify: Restart nginx |
| 103 | + no_log: true |
| 104 | + |
33 | 105 | - name: Restart nginx
|
34 | 106 | ansible.builtin.meta: flush_handlers
|
0 commit comments