how to modify output

Hi folks:

I got the following playbook

Hi

Hi folks:

I got the following playbook


  • hosts: win-ravendb-prd
    tasks:

  • name: Get disk facts
    win_disk_facts:

  • name: Ip address
    debug:
    var: ansible_ip_addresses

  • name: Grab first disk
    set_fact:
    disk: ‘{{ ansible_facts.disks|selectattr(“system_disk”)|first }}’

  • name: Set disk size
    set_fact:
    disksize_gb_human: ‘{{ disk.size|filesizeformat(True) }}’

  • local_action:
    module: copy
    content: “{{ disksize_gb_human }}”
    dest: /tmp/“{{ ansible_ip_addresses | to_nice_json }}”

You’re creating files here with a name that’s json? That’s unusual.

As an output is shows the following:

-rw-r–r-- 1 root root 8 abr 15 15:18 “[? “10.33.80.189”?]”
-rw-r–r-- 1 root root 8 abr 15 15:18 “[? “10.33.80.187”?]”
-rw-r–r-- 1 root root 8 abr 15 15:18 “[? “10.33.80.186”?]”
-rw-r–r-- 1 root root 8 abr 15 15:18 “[? “10.33.80.188”?]”

That’s what you told it to do. The ? Is probably due to the json structure not entirely shown or created as file name.

There is a way to parce the information in order to output without "[?

If you want the files to be named as the IP address (which is an assumption) then tell the copy command to do that, possible using a useful extension, for instance:

dest: “/tmp/{{ ansible_default_ipv4.address }}.txt”

Dick