Hey, you might want to use
- set_fact: machineId={{result.stdout_lines.0}}
as stdout_lines is an array rather than a string. Its hard to tell from
this example because you only have one line in the example. But handy to
know about as sometimes what you need is the contents of the 3rd line or
whatever.
Hope this helps,
Jon
On Tuesday, May 24, 2016 at 9:29:33 PM UTC+1, skinnedknuckles wrote:
>
> Oh, Thanks, yes that was what I needed. Actually here is what I did in my
> playbook...
>
> script: machineId.ps1
> register: result
> - set_fact: machineId={{result.stdout_lines}}
>
>
>
> On Tuesday, May 24, 2016 at 1:59:51 PM UTC-5, skinnedknuckles wrote:
>>
>> Control Node:
>>
>> - CentOS 7
>> - Ansible 2.1
>>
>> Remote Node:
>>
>> - Windows 7
>> - Powershell 3
>>
>> I'm running a powershell script (from my playbook) that returns a number
>> via stdout. How do I assign the result (*6999*) to my playbook variable
>> named machineId?
>>
>> Here's my playbook...
>>
>> ---
>> - name: deploy
>> hosts: windows
>> vars:
>> machineId: none
>> tasks:
>> - name: get machine id
>> script: machineId.ps1
>> register: out
>> - debug: var=out
>>
>> Here's what I get when I run the play book...
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *[ansmgr@dhcp1-60-20 playbooks]$ ansible-playbook deploy.ymlPLAY [deploy
>> new software version] *********************************************TASK
>> [setup]
>> *******************************************************************ok:
>> [ADS-6999]TASK [get machine id]
>> **********************************************************changed:
>> [ADS-6999]TASK [debug]
>> *******************************************************************ok:
>> [ADS-6999] => { "out": { "changed": true, "rc": 0,
>> "stderr": "", "stdout": "6999\n", "stdout_lines":
>> [ "6999" ] }}PLAY RECAP
>> *********************************************************************ADS-6999
>>
>> : ok=3 changed=1 unreachable=0 failed=0 *
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f82c3ebc-6659-40c9-9950-40260f130fcb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.