Powershell util scripts - unable to use Exit-Json or return Json respone to ansible

1,049 views
Skip to first unread message

Amir Luzon

unread,
May 31, 2015, 10:13:29 AM5/31/15
to ansibl...@googlegroups.com
so i have an environment with control machine:
ansible --version
ansible 1.9.1
configured module search path = /usr/share/ansible

i'm trying to use the integrated powershell utilities for sending and returning (Exit-Json, Fail-Json) but the powershell script i am using does not recognize these:

changed: [] => {"changed": true, "rc": 0, "stderr": "Set-Attr : The term 'Set-Attr' is not recognized as the name of a cmdlet, \r\nfunction, script file, or operable program. Check the spelling of the name, or \r\nif a path was included, verify that the path is correct and try again...

i am new to ansible and maybe i am missing something here, please assist.

here is the playbook:
---
- hosts: [MYHOSTS]
  gather_facts: no
  tasks:
   - name: Run powershell test script
     script: scripts/test.ps1

here is the script test.ps1:
#!powershell
# WANT_JSON
# POWERSHELL_COMMON

$result = New-Object psobject
Set-Attr $result "changed" $true
Exit-Json $result



Chris Church

unread,
May 31, 2015, 1:54:25 PM5/31/15
to Amir Luzon, ansibl...@googlegroups.com
The script module (action plugin) uploads and runs the script as-is on the remote machine.

The code in powershell.ps1 is only available to modules and is inserted in place of the # POWERSHELL_COMMON comment before the module is uploaded and run.

If you want to use your script as a module instead, just place it in a library directory alongside your playbook and update your playbook to use it as a module, e.g.:

---

- hosts: [MYHOSTS]
  gather_facts: no
  tasks:
   - name: Run powershell test module
     action: test



--
You received this message because you are subscribed to the Google Groups "Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Amir Luzon

unread,
Jun 1, 2015, 4:05:41 AM6/1/15
to ansibl...@googlegroups.com, cedr...@gmail.com
Thanks for the info that did it :)
Reply all
Reply to author
Forward
0 new messages