# Need to Extract data from the Ansible debug out put

**URL:** <https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [November 13, 2019, 4:40pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652 "2019-11-13T16:40:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [November 13, 2019, 4:40pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/1 "2019-11-13T16:40:06Z")

</div>

Hi ,

I have an playbook for Vmware Powercli :

tasks:

- name: Run PowerShellGet VM script  
command: pwsh /tmp/vcsa\_getVM.ps1  
ignore\_errors: yes  
changed\_when: false  
register: powershell\_output\_getVM

- name: Debug GetVM output  
debug:  
msg:

- “{{ powershell\_output\_getVM.stdout\_lines }}”

Out put:

TASK [Debug GetVM output] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [localhost] =\> {  
“msg”: [  
[  
“”,  
“Name PowerState Num CPUs MemoryGB”,  
“---- ---------- -------- --------”,  
“BVI12DS2 PoweredOn 4 4.000”,  
“BVI13PL1 PoweredOn 8 16.000”,  
“BVI06ID1 PoweredOn 4 4.000”,  
“BVI14PL1 PoweredOn 8 16.000”,  
“BVI10VA1 PoweredOn 4 4.000”,  
“BVI13CS1 PoweredOn 4 8.000”,

I want my o/p should only be list of the following:

BVI12DS2  
BVI13PL1  
BVI06ID1  
BVI14PL1  
BVI10VA1  
BVI13CS1

---

<div class="post-metadata">

**Author:** ![sdoran](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sdoran](https://forum.ansible.com/u/sdoran)\
**Post date:** [November 13, 2019, 7:10pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/2 "2019-11-13T19:10:58Z")

</div>

Rakesh,

Either massage the data with a shell task using grep and cut, or write a custom info module in order to manipulate the data in Python.

This shell task might get you what you need, then use the value of 'stdout\_lines'.

- shell: pwsh /tmp/vcsa\_getVM.ps1 | grep -Ev '^(Name|-+)' | cut -d ' ' -f 1

---

<div class="post-metadata">

**Author:** ![jborean](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jborean/32/1525_2.png) [@jborean](https://forum.ansible.com/u/jborean)\
**Post date:** [November 13, 2019, 8:14pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/3 "2019-11-13T20:14:39Z")

</div>

You could use something like grep to extract it but you could also add the following in your powershell script

`

> Select-Object -ExpandProperty Name

`

This must come after your Get-\* cmdlet call, i.e. ‘Get-VMs | Select-Object -ExpandProperty Name’. This works by taking in the output from the cmdlet and outputting only the values of the Name property.

Thanks

Jordan

---

<div class="post-metadata">

**Author:** ![Akasurde](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akasurde/32/230_2.png) [@Akasurde](https://forum.ansible.com/u/Akasurde)\
**Post date:** [November 14, 2019, 4:27am UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/4 "2019-11-14T04:27:51Z")

</div>

Hi Rakesh,

I agree with Sam and Jordan. You can take a look at this custom VMware powershell modules to write your own - [https://github.com/Akasurde/ansible-vmware\_update\_manager](https://github.com/Akasurde/ansible-vmware_update_manager)

Thanks

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [November 14, 2019, 1:17pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/5 "2019-11-14T13:17:31Z")

</div>

Hi Jordan ,

Thanks for your suggestion .

It worked for some extent , now iam getting the o/p as below. Actually i am new to PowerCLI so dont have much idea on PowerCLi cmdlets, But is there a way to remove the inverted commas and Comma using the PowerCLi Commad.

“BVI12DS2”,  
“BVI13PL1”,  
“BVI06ID1”,  
“BVI14PL1”,  
“BVI10VA1”,  
“BVI13CS1”,  
“BVI03CA1”,  
“BVI13SC2”,  
“BVI12DB2”,  
“BVI05CS2”,  
“BVI04OR2”,

Is there a way to remove the Special charecters using the command input.

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [November 14, 2019, 1:21pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/6 "2019-11-14T13:21:10Z")

</div>

Hi Abhijeet and Sam,

Actually the Vcenter in my organisation has policy enforced not have SSL connectivity , so i cld nt use ansible vm-modules . That is why i had to switch to PWSH using ansible.  
Jordan’s Suggestion worked . But i need to figure out how to remove special characters from o/p using PowerCLi cmds

---

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [November 14, 2019, 1:23pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/7 "2019-11-14T13:23:05Z")

</div>

Here is my script whcih i am using:

Connect-VIServer -Server x.x.x.x -User:xxxxx.com\yyyy -Password:zzzz | Out-Null  
$result = Get-VM -Name BV\* |Where-object {$\_.powerstate -eq “poweredon”} | Select-Object -ExpandProperty Name  
$result

---

<div class="post-metadata">

**Author:** ![The\_Vandyy\_Vines](https://avatars.discourse-cdn.com/v4/letter/t/7993a0/32.png) [@The\_Vandyy\_Vines](https://forum.ansible.com/u/The_Vandyy_Vines)\
**Post date:** [November 14, 2019, 1:25pm UTC](https://forum.ansible.com/t/need-to-extract-data-from-the-ansible-debug-out-put/31652/8 "2019-11-14T13:25:25Z")

</div>

If you want to remove “” via ansible , thats possible
