I try to install NGINX from an Ansible playbook.
Currently I use this playbook to install it:
---
- hosts: all
gather_facts: true
become: true
become_user: root
tasks:
- apt:
name: nginx
when: ansible_os_family == "Debian"
And it works:
Identity added: /runner/artifacts/46/ssh_key_data (root@debian)
SSH password:
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.75]
TASK [apt] *********************************************************************
changed: [192.168.1.75]
PLAY RECAP *********************************************************************
192.168.1.75 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
But I would like to see the state of the NGINX service at the end of my playbook, like that:
Identity added: /runner/artifacts/46/ssh_key_data (root@debian)
SSH password:
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.1.75]
TASK [apt] *********************************************************************
changed: [192.168.1.75]
TASK [Verify nginx state] *********************************************************************
nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-02-14 17:59:13 CET; 20s ago
Docs: man:nginx(8)
Process: 1723 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1724 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1907 (nginx)
Tasks: 2 (limit: 445)
Memory: 5.6M
CPU: 99ms
CGroup: /system.slice/nginx.service
├─1907 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─1910 nginx: worker process
PLAY RECAP *********************************************************************
192.168.1.75 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Or something similar.
How can this be achieved?
3
Answers
you could get that detail from the sudo command here
or even better
Regarding your requirement
it is recommended just to use the
systemd
module.For later check of specific services you can use
service_facts
.