Hi,
I have a small Ansible playbook.
-----------------%<-----------------
-
hosts: localhost
tasks: -
name: Populate service facts
ansible.builtin.service_facts: -
name: Print service facts
loop: -
postfix
-
rsyslog
-
sshd
ansible.builtin.debug:
var: ansible_facts.services[‘{{ item }}.service’][‘state’]
-----------------%<-----------------
The output is
-----------------%<-----------------
PLAY [localhost] ***************************************************************
TASK [Gathering Facts] *********************************************************
ok: [localhost]
TASK [Populate service facts] **************************************************
ok: [localhost]
TASK [Print service facts] *****************************************************
ok: [localhost] => (item=postfix) => {
“ansible_facts.services[‘postfix.service’][‘state’]”: “running”,
“ansible_loop_var”: “item”,
“item”: “postfix”
}
ok: [localhost] => (item=rsyslog) => {
“ansible_facts.services[‘rsyslog.service’][‘state’]”: “running”,
“ansible_loop_var”: “item”,
“item”: “rsyslog”
}
ok: [localhost] => (item=sshd) => {
“ansible_facts.services[‘sshd.service’][‘state’]”: “running”,
“ansible_loop_var”: “item”,
“item”: “sshd”
}
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
-----------------%<-----------------
What I want is
TASK [Print service facts]
should print only
“ansible_facts.services[‘rsyslog.service’][‘state’]”: “running”
The other three should be hidden.
Any easy trick for this ?
Thanks