# unable to  get the output with specific inventory\_hostname

**URL:** <https://forum.ansible.com/t/unable-to-get-the-output-with-specific-inventory-hostname/29432>\
**Category:** Ansible Project\
**Created:** [January 13, 2019, 8:27pm UTC](https://forum.ansible.com/t/unable-to-get-the-output-with-specific-inventory-hostname/29432 "2019-01-13T20:27:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinesh\_Singh](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Dinesh\_Singh](https://forum.ansible.com/u/Dinesh_Singh)\
**Post date:** [January 13, 2019, 8:27pm UTC](https://forum.ansible.com/t/unable-to-get-the-output-with-specific-inventory-hostname/29432/1 "2019-01-13T20:27:49Z")

</div>

Hi Everyone,

Im trying to fetch output for yum check-update and export the output to a csv file for multiple hosts. but im unable to replace empty line with IP address of each server from inventory\_hostname (which is ip address) help would be greatly appreciated.

here is my playbook:

- name: Playbook to get patch details from Linux Servers  
hosts: all  
tasks:

- name: remove the file  
shell: ‘\> /tmp/patch-updates.csv’

- name: Get the Package list  
shell: ‘yum check-update || test $? -eq 100’  
register: result

- debug:

msg: “{{ ansible\_distribution }}-{{ ansible\_distribution\_version }}”

- set\_fact:

# myvalue: “{{ result.stdout\_lines[0] }}”

# myvalue: “{{ result.stdout\_lines[0] | default([{{ ansible\_all\_ipv4\_addresses }}]) }}”

# myvalue: “{{ result.stdout\_lines[0] |regex\_replace(‘(0)’, ‘test’)}}”

myvalue: “{{ result.stdout\_lines[0] | regex\_replace(‘\n\*$’, ‘ansible\_hostname’) }}”  
vars:  
regexp: ‘^\s\*$’  
replace: ‘{{ inventory\_hostname }}’

- debug:  
var: myvalue

- debug: var=result.stdout\_lines

- name: If no patches or already upto date

fail: msg=“{{ ansible\_host }} already upto date or no patches available”  
when: result.stdout == “”

- name: Saving output into csv file  
local\_action:  
lineinfile  
line={{ result.stdout }} path=/tmp/patch-updates.csv  
when: result.stdout != “”

- name: Replace the space with comma  
shell: sed -i -e ‘s/ {1,}/,/g’ /tmp/patch-updates.csv  
when: result.stdout != “”  
notify: send mail

- name: Replace Empty line with IP  
replace:  
path: /tmp/patch-updates.csv  
regexp: ‘^\s\*$’  
replace: ‘{{ inventory\_hostname }}’  
handlers:

- name: send mail  
mail:  
port: 25  
body: “Hello, \n\n This is auto generated report for available patch updates for Distribution Version. \n\n\n\n Please find the attached report”  
attach: /tmp/patch-updates.csv  
charset: utf8  
delegate\_to: localhost  
run\_once: True
