0
- name: Check the VolumeGroup has 5gb space
  assert:
    that: ansible_lvm.vgs.VG00.free_g|int >= 5
    fail_msg: 'VG has no free space'
    success_msg: "{{ ansible_lvm.vgs.rhel.free_g }}"
  register: vg00
- name: Line in file
  shell: echo -e "{{ ansible_fqdn }},VG_FREE=0" >> /tmp/failed.txt
  delegate_to: localhost
  when: "'FATAL' in vg00"

I need only the failed hosts to be redirected using when condition but it is not working. Any different condition will help

1
  • I need only the failed hosts to be redirected using when condition but it is not working. Any different condition will help – pugazhendhi Aug 18 '20 at 15:51
1

It seems like you are trying to use facts that do not exist (I've checked in ansible 2.9.12).

So my way of getting this to work would be:

---
- name: answer stack overflow
  hosts: all
  become: yes

  tasks:
    - name: Get VolumeGroup "mirror" free space in GB
      shell: vgs --units G|grep mirror|awk '{print $NF}'|tr -d 'G'
      register: vg_free
    - name: report your findings
      shell: echo {{ ansible_hostname }} has {{ vg_free.stdout }} GB free on VG mirror >> /tmp/hosts_with_vg_less_than_5GB_free_report.txt
      delegate_to: localhost
      when: {{ vg_free.stdout | int }} < 5

Using shell module extensively is not recommended as Idempotence (https://en.wikipedia.org/wiki/Idempotence) is hard to achieve but for reporting purposes - why not :) .

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.