Hi Jon,

I'm just starting out with Ansible so I haven't created any roles, nor am I 
using any that anyone else created.

The file is in the */etc/ansible/files *directory.

Escaping the spaces didn't work. And it definitely seems like it's Ansible 
itself that fails to parse the spaces, at least based on the error message.

I tried changing `script` to this:

```
    script: ./files/name\ of\ a\ script.ps1 -Param1 {{ variable_name }}
```

But I get the same error as before.

I got it to work by renaming the script and replacing the spaces with 
underscores; the updated `script`:

```
  script: "./files/name_of_a_script.ps1 -Param1 {{ variable_name }}"
```

It also worked without quoting:

```
  script: ./files/name_of_a_script.ps1 -Param1 {{ variable_name }}
```

I'll take a look at creating a module for this. That'd certainly be a 
little cleaner than adding an additional task to save some info to a 
register variable and use that to implement a custom `changed_when` setting 
for this task.

But just for clarification – *should *the script module support scripts 
with spaces in their path on Windows hosts?

Thanks,
Kenny

On Wednesday, June 22, 2016 at 7:06:53 AM UTC-4, J Hawkesworth wrote:
>
> 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/0ea021c5-13c5-4733-b7ca-ecad15a6113e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to