2021-12-07 02:47:13 +01:00
|
|
|
---
|
|
|
|
- name: Verify
|
|
|
|
hosts: all
|
|
|
|
tasks:
|
|
|
|
- name: Check if NGINX is installed
|
|
|
|
package:
|
|
|
|
name: nginx
|
|
|
|
state: present
|
|
|
|
check_mode: true
|
|
|
|
register: install
|
|
|
|
failed_when: (install is changed) or (install is failed)
|
|
|
|
|
|
|
|
- name: Check if NGINX service is running
|
|
|
|
service:
|
|
|
|
name: nginx
|
|
|
|
state: started
|
|
|
|
enabled: true
|
|
|
|
check_mode: true
|
|
|
|
register: service
|
|
|
|
failed_when: (service is changed) or (service is failed)
|
|
|
|
|
|
|
|
- name: Verify NGINX is up and running
|
|
|
|
uri:
|
|
|
|
url: http://localhost
|
|
|
|
status_code: 200
|
|
|
|
|
2022-02-02 19:01:38 +01:00
|
|
|
- name: Fetch NGINX version
|
|
|
|
uri:
|
|
|
|
url: https://version.nginx.com/nginx/mainline
|
|
|
|
return_content: true
|
|
|
|
check_mode: false
|
|
|
|
register: nginx_versions
|
|
|
|
|
|
|
|
- name: Set NGINX version
|
|
|
|
set_fact:
|
|
|
|
nginx_version: "{{ nginx_versions.content | regex_search('([0-9]+\\.){2}[0-9]+') }}"
|
|
|
|
|
2021-12-07 02:47:13 +01:00
|
|
|
- name: Verify NGINX has been upgraded
|
|
|
|
command: nginx -v
|
|
|
|
args:
|
|
|
|
chdir: "{{ ((ansible_facts['system'] | lower is not search('bsd')) | ternary('/etc/nginx', '/usr/local/sbin')) }}"
|
|
|
|
changed_when: false
|
|
|
|
register: version
|
2022-02-02 19:01:38 +01:00
|
|
|
failed_when: version is not search(nginx_version)
|