nginx(role): use better naming, wording and file structure
This commit is contained in:
		
					parent
					
						
							
								9b2ef55f86
							
						
					
				
			
			
				commit
				
					
						344dd78981
					
				
			
		
					 6 changed files with 55 additions and 58 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| - name: Restart `nginx.service` | - name: Restart nginx | ||||||
|   ansible.builtin.systemd: |   ansible.builtin.systemd: | ||||||
|     name: nginx.service |     name: nginx.service | ||||||
|     state: restarted |     state: restarted | ||||||
|  |  | ||||||
|  | @ -1,14 +1,11 @@ | ||||||
| - name: make sure nginx configuration names are valid | - name: Ensure valid configuration names | ||||||
|   ansible.builtin.include_role: |   ansible.builtin.import_tasks: | ||||||
|     name: nginx |     file: main/01_validate_config_names.yaml | ||||||
|     tasks_from: make_sure_nginx_configuration_names_are_valid |  | ||||||
| 
 | 
 | ||||||
| - name: ensure NGINX is installed | - name: Ensure nginx is installed | ||||||
|   ansible.builtin.include_role: |   ansible.builtin.import_tasks: | ||||||
|     name: nginx |     file: main/02_nginx_install.yaml | ||||||
|     tasks_from: main/nginx_install |  | ||||||
| 
 | 
 | ||||||
| - name: make sure desirable NGINX configs are deployed | - name: Ensure configuration deployment | ||||||
|   ansible.builtin.include_role: |   ansible.builtin.import_tasks: | ||||||
|     name: nginx |     file: main/03_config_deploy.yaml | ||||||
|     tasks_from: main/config_deploy |  | ||||||
|  |  | ||||||
							
								
								
									
										7
									
								
								roles/nginx/tasks/main/01_validate_config_names.yaml
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								roles/nginx/tasks/main/01_validate_config_names.yaml
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,7 @@ | ||||||
|  | - name: Ensure that the given configuration names are valid | ||||||
|  |   ansible.builtin.fail: | ||||||
|  |     msg: "You used one of the reserved configuration names: '{{ item.name }}'." | ||||||
|  |   when: item.name == "tls" | ||||||
|  |         or item.name == "redirect" | ||||||
|  |         or item.name == "logging" | ||||||
|  |   loop: "{{ nginx__configurations }}" | ||||||
|  | @ -4,7 +4,7 @@ | ||||||
|     state: present |     state: present | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
| - name: make sure NGINX signing key is added | - name: Ensure NGINX signing key is added | ||||||
|   ansible.builtin.get_url: |   ansible.builtin.get_url: | ||||||
|     url: https://nginx.org/keys/nginx_signing.key |     url: https://nginx.org/keys/nginx_signing.key | ||||||
|     dest: /etc/apt/trusted.gpg.d/nginx.asc |     dest: /etc/apt/trusted.gpg.d/nginx.asc | ||||||
|  | @ -13,19 +13,19 @@ | ||||||
|     group: root |     group: root | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
| - name: make sure NGINX APT repository is added | - name: Ensure NGINX APT repository is added | ||||||
|   ansible.builtin.apt_repository: |   ansible.builtin.apt_repository: | ||||||
|     repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/nginx.asc] https://nginx.org/packages/debian/ {{ ansible_distribution_release }} nginx" |     repo: "deb [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/nginx.asc] https://nginx.org/packages/debian/ {{ ansible_distribution_release }} nginx" | ||||||
|     state: present |     state: present | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
| - name: make sure NGINX APT source repository is added | - name: Ensure NGINX APT source repository is added | ||||||
|   ansible.builtin.apt_repository: |   ansible.builtin.apt_repository: | ||||||
|     repo: "deb-src [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/nginx.asc] https://nginx.org/packages/debian/ {{ ansible_distribution_release }} nginx" |     repo: "deb-src [arch=amd64 signed-by=/etc/apt/trusted.gpg.d/nginx.asc] https://nginx.org/packages/debian/ {{ ansible_distribution_release }} nginx" | ||||||
|     state: present |     state: present | ||||||
|   become: true |   become: true | ||||||
| 
 | 
 | ||||||
| - name: set up repository pinning to make sure nginx package gets installed from NGINX repositories | - name: Ensure repository pinning to make sure nginx package gets installed from NGINX repositories is set up | ||||||
|   ansible.builtin.copy: |   ansible.builtin.copy: | ||||||
|     content: | |     content: | | ||||||
|       Package: * |       Package: * | ||||||
|  | @ -1,13 +1,13 @@ | ||||||
| - name: check, if a save of a previous `nginx.conf` is present | - name: Check, if a save of a previous `nginx.conf` is present | ||||||
|   ansible.builtin.stat: |   ansible.builtin.stat: | ||||||
|     path: /etc/nginx/nginx.conf.ansiblesave |     path: /etc/nginx/nginx.conf.ansiblesave | ||||||
|   register: nginx__nginx_conf_ansiblesave_stat_result |   register: nginx__nginx_conf_ansiblesave_stat | ||||||
| 
 | 
 | ||||||
| - name: handle the case, where a custom `nginx.conf` is to be used | - name: Handle the case, where a custom `nginx.conf` is to be used | ||||||
|   when: nginx__use_custom_nginx_conf |   when: nginx__use_custom_nginx_conf | ||||||
|   block: |   block: | ||||||
|     - name: when no `nginx.conf.ansiblesave` is present, save the current `nginx.conf` |     - name: When no `nginx.conf.ansiblesave` is present, save the current `nginx.conf` | ||||||
|       when: not nginx__nginx_conf_ansiblesave_stat_result.stat.exists |       when: not nginx__nginx_conf_ansiblesave_stat.stat.exists | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         force: true |         force: true | ||||||
|         dest: /etc/nginx/nginx.conf.ansiblesave |         dest: /etc/nginx/nginx.conf.ansiblesave | ||||||
|  | @ -18,7 +18,7 @@ | ||||||
|         src: /etc/nginx/nginx.conf |         src: /etc/nginx/nginx.conf | ||||||
|       become: true |       become: true | ||||||
| 
 | 
 | ||||||
|     - name: deploy the custom `nginx.conf` |     - name: Ensure the custom `nginx.conf` is deployed | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         content: "{{ nginx__custom_nginx_conf }}" |         content: "{{ nginx__custom_nginx_conf }}" | ||||||
|         dest: "/etc/nginx/nginx.conf" |         dest: "/etc/nginx/nginx.conf" | ||||||
|  | @ -26,13 +26,13 @@ | ||||||
|         owner: root |         owner: root | ||||||
|         group: root |         group: root | ||||||
|       become: true |       become: true | ||||||
|       notify: Restart `nginx.service` |       notify: Restart nginx | ||||||
| 
 | 
 | ||||||
| - name: handle the case, where no custom `nginx.conf` is to be used | - name: Handle the case, where no custom `nginx.conf` is to be used | ||||||
|   when: not nginx__use_custom_nginx_conf |   when: not nginx__use_custom_nginx_conf | ||||||
|   block: |   block: | ||||||
|     - name: when a `nginx.conf.ansiblesave` is present, copy it to `nginx.conf` |     - name: When a `nginx.conf.ansiblesave` is present, copy it to `nginx.conf` | ||||||
|       when: nginx__nginx_conf_ansiblesave_stat_result.stat.exists |       when: nginx__nginx_conf_ansiblesave_stat.stat.exists | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         force: true |         force: true | ||||||
|         dest: /etc/nginx/nginx.conf |         dest: /etc/nginx/nginx.conf | ||||||
|  | @ -42,32 +42,32 @@ | ||||||
|         remote_src: true |         remote_src: true | ||||||
|         src: /etc/nginx/nginx.conf.ansiblesave |         src: /etc/nginx/nginx.conf.ansiblesave | ||||||
|       become: true |       become: true | ||||||
|       notify: Restart `nginx.service` |       notify: Restart nginx | ||||||
| 
 | 
 | ||||||
|     - name: delete the `nginx.conf.ansiblesave`, if it is present |     - name: Ensure no `nginx.conf.ansiblesave` is present | ||||||
|       when: nginx__nginx_conf_ansiblesave_stat_result.stat.exists |       when: nginx__nginx_conf_ansiblesave_stat.stat.exists | ||||||
|       ansible.builtin.file: |       ansible.builtin.file: | ||||||
|         path: /etc/nginx/nginx.conf.ansiblesave |         path: /etc/nginx/nginx.conf.ansiblesave | ||||||
|         state: absent |         state: absent | ||||||
|       become: true |       become: true | ||||||
| 
 | 
 | ||||||
| - name: make sure mozilla dhparam is deployed | - name: Ensure mozilla dhparam is deployed | ||||||
|   ansible.builtin.get_url: |   ansible.builtin.get_url: | ||||||
|     force: true |     force: true | ||||||
|     dest: /etc/nginx-mozilla-dhparam |     dest: /etc/nginx-mozilla-dhparam | ||||||
|     mode: "0644" |     mode: "0644" | ||||||
|     url: https://ssl-config.mozilla.org/ffdhe2048.txt |     url: https://ssl-config.mozilla.org/ffdhe2048.txt | ||||||
|   become: true |   become: true | ||||||
|   notify: Restart `nginx.service` |   notify: Restart nginx | ||||||
| 
 | 
 | ||||||
| - name: set `nginx__config_files_to_exist` fact initially to an empty list | - name: Set `nginx__config_files_to_exist` fact initially to an empty list | ||||||
|   ansible.builtin.set_fact: |   ansible.builtin.set_fact: | ||||||
|     nginx__config_files_to_exist: [ ] |     nginx__config_files_to_exist: [ ] | ||||||
| 
 | 
 | ||||||
| - name: handle the case, where tls.conf should be deployed | - name: Handle the case, where tls.conf should be deployed | ||||||
|   when: nginx__deploy_tls_conf |   when: nginx__deploy_tls_conf | ||||||
|   block: |   block: | ||||||
|     - name: make sure tls.conf is deployed |     - name: Ensure tls.conf is deployed | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         force: true |         force: true | ||||||
|         dest: /etc/nginx/conf.d/tls.conf |         dest: /etc/nginx/conf.d/tls.conf | ||||||
|  | @ -76,16 +76,16 @@ | ||||||
|         group: root |         group: root | ||||||
|         src: tls.conf |         src: tls.conf | ||||||
|       become: true |       become: true | ||||||
|       notify: Restart `nginx.service` |       notify: Restart nginx | ||||||
| 
 | 
 | ||||||
|     - name: add tls.conf to nginx__config_files_to_exist |     - name: Add tls.conf to nginx__config_files_to_exist | ||||||
|       ansible.builtin.set_fact: |       ansible.builtin.set_fact: | ||||||
|         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'tls.conf' ] }}"  # noqa: jinja[spacing] |         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'tls.conf' ] }}"  # noqa: jinja[spacing] | ||||||
| 
 | 
 | ||||||
| - name: handle the case, where redirect.conf should be deployed | - name: Handle the case, where redirect.conf should be deployed | ||||||
|   when: nginx__deploy_redirect_conf |   when: nginx__deploy_redirect_conf | ||||||
|   block: |   block: | ||||||
|     - name: make sure redirect.conf is deployed |     - name: Ensure redirect.conf is deployed | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         force: true |         force: true | ||||||
|         dest: /etc/nginx/conf.d/redirect.conf |         dest: /etc/nginx/conf.d/redirect.conf | ||||||
|  | @ -94,16 +94,16 @@ | ||||||
|         group: root |         group: root | ||||||
|         src: redirect.conf |         src: redirect.conf | ||||||
|       become: true |       become: true | ||||||
|       notify: Restart `nginx.service` |       notify: Restart nginx | ||||||
| 
 | 
 | ||||||
|     - name: add redirect.conf to nginx__config_files_to_exist |     - name: Add redirect.conf to nginx__config_files_to_exist | ||||||
|       ansible.builtin.set_fact: |       ansible.builtin.set_fact: | ||||||
|         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'redirect.conf' ] }}"  # noqa: jinja[spacing] |         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'redirect.conf' ] }}"  # noqa: jinja[spacing] | ||||||
| 
 | 
 | ||||||
| - name: handle the case, where logging.conf should be deployed | - name: Handle the case, where logging.conf should be deployed | ||||||
|   when: nginx__deploy_logging_conf |   when: nginx__deploy_logging_conf | ||||||
|   block: |   block: | ||||||
|     - name: make sure logging.conf is deployed |     - name: Ensure logging.conf is deployed | ||||||
|       ansible.builtin.copy: |       ansible.builtin.copy: | ||||||
|         force: true |         force: true | ||||||
|         dest: /etc/nginx/conf.d/logging.conf |         dest: /etc/nginx/conf.d/logging.conf | ||||||
|  | @ -112,13 +112,13 @@ | ||||||
|         group: root |         group: root | ||||||
|         src: logging.conf |         src: logging.conf | ||||||
|       become: true |       become: true | ||||||
|       notify: Restart `nginx.service` |       notify: Restart nginx | ||||||
| 
 | 
 | ||||||
|     - name: add logging.conf to nginx__config_files_to_exist |     - name: Add logging.conf to nginx__config_files_to_exist | ||||||
|       ansible.builtin.set_fact: |       ansible.builtin.set_fact: | ||||||
|         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'logging.conf' ] }}"  # noqa: jinja[spacing] |         nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ 'logging.conf' ] }}"  # noqa: jinja[spacing] | ||||||
| 
 | 
 | ||||||
| - name: make sure all given configuration files are deployed | - name: Ensure all given configuration files are deployed | ||||||
|   ansible.builtin.copy: |   ansible.builtin.copy: | ||||||
|     content: "{{ item.content }}" |     content: "{{ item.content }}" | ||||||
|     dest: "/etc/nginx/conf.d/{{ item.name }}.conf" |     dest: "/etc/nginx/conf.d/{{ item.name }}.conf" | ||||||
|  | @ -127,24 +127,24 @@ | ||||||
|     group: root |     group: root | ||||||
|   become: true |   become: true | ||||||
|   loop: "{{ nginx__configurations }}" |   loop: "{{ nginx__configurations }}" | ||||||
|   notify: Restart `nginx.service` |   notify: Restart nginx | ||||||
| 
 | 
 | ||||||
| - name: add names plus suffix from `nginx__configurations` to `nginx__config_files_to_exist` fact | - name: Add names with suffixes from `nginx__configurations` to `nginx__config_files_to_exist` fact | ||||||
|   ansible.builtin.set_fact: |   ansible.builtin.set_fact: | ||||||
|     nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ item.name + '.conf' ] }}"  # noqa: jinja[spacing] |     nginx__config_files_to_exist: "{{ nginx__config_files_to_exist + [ item.name + '.conf' ] }}"  # noqa: jinja[spacing] | ||||||
|   loop: "{{ nginx__configurations }}" |   loop: "{{ nginx__configurations }}" | ||||||
| 
 | 
 | ||||||
| - name: find configuration files to remove | - name: Find configuration files to remove | ||||||
|   ansible.builtin.find: |   ansible.builtin.find: | ||||||
|     paths: /etc/nginx/conf.d/ |     paths: /etc/nginx/conf.d/ | ||||||
|     recurse: false |     recurse: false | ||||||
|     excludes: "{{ nginx__config_files_to_exist }}" |     excludes: "{{ nginx__config_files_to_exist }}" | ||||||
|   register: nginx__config_files_to_remove |   register: nginx__config_files_to_remove | ||||||
| 
 | 
 | ||||||
| - name: remove all configuration file, which should be removed | - name: Remove all configuration file, which should be removed | ||||||
|   ansible.builtin.file: |   ansible.builtin.file: | ||||||
|     path: "{{ item.path }}" |     path: "{{ item.path }}" | ||||||
|     state: absent |     state: absent | ||||||
|   become: true |   become: true | ||||||
|   loop: "{{ nginx__config_files_to_remove.files }}" |   loop: "{{ nginx__config_files_to_remove.files }}" | ||||||
|   notify: Restart `nginx.service` |   notify: Restart nginx | ||||||
|  | @ -1,7 +0,0 @@ | ||||||
| - name: make sure nginx configuration names are valid |  | ||||||
|   ansible.builtin.fail: |  | ||||||
|     msg: "You used the following name: `{{ item.name }}`. Please make sure to not use the following names: `tls`, `redirect`." |  | ||||||
|   when: item.name == "tls" |  | ||||||
|         or item.name == "redirect" |  | ||||||
|         or item.name == "logging" |  | ||||||
|   loop: "{{ nginx__configurations }}" |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue