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