1) How can I NOT print what server2 is printing/showing?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5617fb1f-3aa7-45a3-ba84-656b7b786c86n%40googlegroups.com.
- name: Get stat for /var/log/messages ansible.builtin.stat: path: /var/log/messages register: messages_files - name: What to do about missing /var/log/messages? ansible.builtin.debug: msg: '{{ inventory_hostname }} has no /var/log/messages. Now what?' when: not messages_files.stat.exists - name: Restart syslog if /var/log/messages is zero-length ansible.builtin.service: name: syslog state: restarted when: messages_files.stat.exists and messages_files.stat.size == 0There's no need to start another play to do the service restarts.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/92d08bef-67eb-46d5-a2c1-6bcb75d2e262n%40googlegroups.com.
-- Todd
Well, the set_fact is supposed to only register or select anything where the size parameter of the files attributes is 0. The ones that are printing just [] don't fit that criteria, and therefore, shouldn't be included in the debug output. Yet they are, so that's what I'm trying to fix/clean up first.
-- Todd
Something like this should work?
---
- hosts: my_hosts
become: true
become_method: sudo
gather_facts: false
tasks:
- name: Determine if /var/log/messages is zero-length
ansible.builtin.find:
paths: /var/log
patterns: messages
register: messages_files
- name: Check if /var/log/messages is zero length
ansible.builtin.stat:
path: "{{ item.path }}"
register: file_details
with_items: "{{ messages_files.files }}"
when: messages_files.matched > 0
- name: Restart rsyslog service if /var/log/messages is zero length
ansible.builtin.systemd:
name: rsyslog
state: restarted
when: item.stat.exists and item.stat.size == 0
with_items: "{{ file_details.results }}"
From: ansible...@googlegroups.com <ansible...@googlegroups.com>
On Behalf Of lift...@gmail.com
Sent: Wednesday, April 24, 2024 8:27 PM
To: Ansible Project <ansible...@googlegroups.com>
Subject: [ansible-project] Getting hostnames from a fact
You don't often get email from lift...@gmail.com. Learn why this is important |
Caution: This email originated from outside of the organisation. Do not click links or open attachments unless you recognise the sender and know the content is safe |
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
ansible-proje...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5617fb1f-3aa7-45a3-ba84-656b7b786c86n%40googlegroups.com.
Proud to be a certified B Corporation
This message is private and confidential. If you have received this message in error, please notify us and remove it from your system.
Zen Internet Limited may monitor email traffic data to manage billing, to handle customer enquiries, and for the prevention and detection of fraud. We may also monitor the content of emails sent to and/or
from Zen Internet Limited for the purposes of security, staff training and to monitor the quality of service.
Zen Internet Limited is registered in England and Wales, Sandbrook Park, Sandbrook Way, Rochdale, OL11 1RY Company No. 03101568 VAT Reg No. 686 0495 01