Dear All,
I am executing the df -kh command saving the result in csv but result is not coming in proper csv format.
--------Playbook--------
Dear All,
I am executing the df -kh command saving the result in csv but result is not coming in proper csv format.
--------Playbook--------
Hello,
Dear All,
I am executing the df -kh command saving the result in csv but result is not coming in proper csv format.
--------Playbook--------
name: Generate the disk spacke in csvormat
hosts: all
tasks:name: disk space
shell: “df -kh”
register: shell_outputset_fact: t1=“{{ hostvars[inventory_hostname][‘shell_output’][‘stdout_lines’] }}”
debug: var=t1
name: Generate Report
template:
src: hosts.j2
dest: /tmp/host_report.csv
delegate_to: localhost
run_once: yes-------template: -----------
#SNo., Filesystem, Size, Used, Avail, Use%, Mounted on
{% for hostnode in ansible_play_hosts %}
{{ loop.index }},{{ t1 }},{{ hostnode }}{% endfor %}
-please advice…
You did not tell us what kind of problems you encountered and may be what you expect. Typically, many people - including me - do not answer.
Thus, missing problem description:
Solutions
(1) make a second loop in hosts.j2 for the lines in t1
(2) use some expression to replace one or more whitespaces with a ‘,’
(3) not addressed, this remains to you
{% for hostnode in ansible_play_hosts %}
{% for df_line in t1 %}
{{ loop.index }},{{ df_line | regex_replace(‘\s+’, ‘,’) }},{{ hostnode }}
{% endfor %}
{% endfor %}
BR,
Roland