Arseny Zinchenko
Posted on March 10, 2019
Have a self-written letsencrypt
role (see the Prometheus: RTFM blog monitoring set up with Ansible – Grafana, Loki, and promtail post).
Before running the Let’s Encrypt client to obtain a new certificate – need to check if NGINX is installed on a remote host.
Let’s use the package_facts
module:
...
- name: "Check if NGINX is installed"
package_facts:
manager: "auto"
...
And add a conditional check with when
using the ansible_facts.packages
array:
...
- name: "NGINX test result"
debug:
msg: "NGINX found"
when: "'nginx' in ansible_facts.packages"
- name: "NGINX test result"
debug:
msg: "NGINX NOT found"
when: "'nginx' not in ansible_facts.packages"
Check:
...
TASK [test : Check if NGINX is installed] ****
ok: [ssh.dev.rtfm.co.ua]
TASK [test : NGINX test result] ****
ok: [ssh.dev.rtfm.co.ua] => {
"msg": "NGINX found"
}
TASK [test : NGINX test result] ****
skipping: [ssh.dev.rtfm.co.ua]
PLAY RECAP ****
ssh.dev.rtfm.co.ua : ok=3 changed=0 unreachable=0 failed=0
...
Remove NGINX:
root@rtfm-do-dev:~# apt purge nginx
Run again:
...
TASK [test : Check if NGINX is installed] ****
ok: [ssh.dev.rtfm.co.ua]
TASK [test : NGINX test result] ****
skipping: [ssh.dev.rtfm.co.ua]
TASK [test : NGINX test result] ****
ok: [ssh.dev.rtfm.co.ua] => {
"msg": "NGINX NOT found"
}
PLAY RECAP ****
ssh.dev.rtfm.co.ua : ok=3 changed=0 unreachable=0 failed=0
Done.
Similar posts
- 03/10/2019 Prometheus: RTFM blog monitoring set up with Ansible – Grafana, Loki, and promtail (0)
- 05/22/2018 Ansible: теги, include_vars и приоритеты переменных (0)
- 07/13/2018 Ansible: проверить конфигурацию NGINX перед рестартом (0)
💖 💪 🙅 🚩
Arseny Zinchenko
Posted on March 10, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.