# Ansible set\_fact not working

**URL:** <https://forum.ansible.com/t/ansible-set-fact-not-working/21878>\
**Category:** Ansible Project\
**Created:** [June 28, 2016, 3:59pm UTC](https://forum.ansible.com/t/ansible-set-fact-not-working/21878 "2016-06-28T15:59:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sreenivas\_narayan](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sreenivas\_narayan](https://forum.ansible.com/u/sreenivas_narayan)\
**Post date:** [June 28, 2016, 3:59pm UTC](https://forum.ansible.com/t/ansible-set-fact-not-working/21878/1 "2016-06-28T15:59:27Z")

</div>

I am trying to list the directory size of certain directory in list of servers. In the below playbook the ruby script along with ansible task will create file with all instance details and saving it in region-ec2-list.txt. What I need in lineinfile is to, it should insert the set\_fact output to file /tmp/disk-ec2-list.txt below the line {{ inventory\_hostname }} as the output of the ruby script will have same {{ inventory\_hostname }} , that is public ip

- name: Listing ec2 instance in all regions(us-east-1", “us-west-1”, “us-west-2”, “eu-west-1”, “eu-central-1”, "ap-southeast-2)

local\_action: command /usr/bin/ruby /root/sree/test/list-all.rb “{{ corp\_aws\_key\_id }}” “{{ corp\_aws\_secret\_access\_key }}”  
register: output\_ruby  
run\_once: true

- name: copy output to file  
local\_action: copy content=“{{ output\_ruby.stdout }}” dest=“/tmp/disk-ec2-list.txt”
- name: Execute du -sh /var/lib/mysql  
command: du -sh /var/lib/mysql  
register: disk\_usage\_mysql
- set\_fact: mysql={{ disk\_usage\_mysql.stdout }}
- name: Execute du -sh /usr/local/wdd/wddrdata/attachment  
command: du -sh /usr/local/wdd/wddrdata/attachment  
register: disk\_usage\_wddrdata
- set\_fact: wddrdata={{ disk\_usage\_wddyrdata.stdout }}
- name: debug  
debug: var=“{{ inventory\_hostname }} {{ mysql }} {{ wddrdata }}”
- name: localaction

# local\_action: copy content= “{{ inventory\_hostname }} {{ mysql }} {{ wddrdata }}” dest=“/tmp/disk-ec2-list.txt”

# local\_action: lineinfile dest=/tmp/disk-ec2-list.txt insertafter=EOF line=“{{ inventory\_hostname }} {{ mysql }} {{ wddrdata }}” create=yes

In short: how to insert a file using lineinfile after string “{{ inventory\_hostname }}”

please help. Also let me know if anymore details is required

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [June 29, 2016, 1:57pm UTC](https://forum.ansible.com/t/ansible-set-fact-not-working/21878/2 "2016-06-29T13:57:15Z")

</div>

Something like this

- lineinfile:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/tmp/disk-ec2-list.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;regexp="^{{ wddrdata }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line="{{ wddrdata }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;insertafter="{{ inventory\_hostname }}"
