So just so we are clear... script attempts to pick .ps1 off your ansible
controller and transfer it to the windows node before running it. If you
want to run a .ps1 that is already there right now your only choice is to
use raw.
If your script task is in a role then 'role magic' (as I have just decided
to call it) will find files in the files subdir of your role without
needing a relative path.
So like this ought to at least stop it looking in
/etc/ansible\.files\name... like it is at the moment.
```
- name: Run a script
script: name of a script.ps1 -Param1 {{ variable_name }}
```
You might need to escape the spaces in the file name
```
- name: Run a script
script: name\ of\ a\ script.ps1 -Param1 {{ variable_name }}
```
However, if at all possible, I'd recommend saving yourself some pain and
renaming the .ps1 to avoid spaces, because powershell is very easily
confused when it comes to parameter parsing (especially when calling
external programs from within powershell).
Better still, convert the powershell into an ansible module if at all
possible. That way you can do change detection in the powershell (script
will allways report 'changed'). Its really not that much more work to make
a module - the only extra things are handling the module parameters and
setting up the contents of the object that contains the outcome of the
module.
Hope this helps,
Jon
On Tuesday, June 21, 2016 at 8:43:11 PM UTC+1, Kenny Evitt wrote:
>
> I'm trying to run a (PowerShell) script with a path in its name:
>
> ```
> - name: Run a script
> script: '"./files/name of a script.ps1" -Param1 {{ variable_name }}'
> ```
>
> The above is only the latest attempting at quoting/escaping I've tried.
> Regardless, I get an error like this when I run the playbook containing the
> above task:
>
> ```
> TASK [Run a script] *****************************
> task path: /etc/ansible/playbook.yml:38
> <192.168.200.245> ESTABLISH WINRM CONNECTION FOR USER:
> SOME-HOST\Administrator on PORT 5986 TO 192.168.200.245
> <192.168.200.245> EXEC Set-StrictMode -Version Latest
> (New-Item -Type Directory -Path $env:temp -Name
> "ansible-tmp-1466538051.8-95578181041077").FullName | Write-Host -Separator
> '';
> <192.168.200.245> PUT "/etc/ansible/"./files/name\" TO
> "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1466537998.0-243829631467080\name"
> fatal: [some-host]: FAILED! => {"failed": true, "msg": "file or module
> does not exist: \"/etc/ansible/\"./files/name\\\""}
>
> ```
>
> Any ideas?
>
--
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/724f0b8d-092c-42c4-822e-d1b9fa849e02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.