Thanks Jon. I'll take a look at getting setup soonish so as to be able contribute to (or at least test) any changes for this.
And I am totally going to look into roles. In fact, the playbook I'm working on now – my very first playbook too – is a perfect candidate for a role. I'm also going to take a look at creating modules for my scripts as that's also a nice way to encapsulate 'atomic' changes in playbooks. Yes, Matt, I also asked this on Stack Overflow. Sorry for not being clear initially if you were the person that answered before. I created a 'feature idea' issue for this <https://github.com/ansible/ansible/issues/16414> on the *ansible/ansible *project on GitHub. Thanks, Kenny On Wednesday, June 22, 2016 at 4:33:46 PM UTC-4, Matt Davis wrote: > > I'm assuming you're the one who asked this on StackOverflow recently... > > Please file a bug on this under the ansible/ansible project- it looks like > it's not a Windows-specific issue, given where it's failing. No guarantees > we'll be able to thread the needle correctly for separating the script name > from the args in the free-form script arg, but others have asked for a more > explicit separation between script name and args in our script action, and > this would be an excellent case for it. > > Thanks, > > -Matt > > On Wednesday, June 22, 2016 at 9:59:59 AM UTC-7, J Hawkesworth wrote: >> >> >> Looking at the integration tests for the script module, which you can >> find here, >> https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_win_script/tasks/main.yml >> there >> aren't any tests which demonstrate spaces in the file name, so I think its >> a case of it being something that's not expected. Fortunately being an >> open source project anyone who is troubled by it can dig in and propose an >> enhancement. >> >> I'd strongly recommend having a look at roles as they are a great 'unit >> of reuse'. I prefer modules to be small and do one thing well as that >> makes them much more re-usable and composable with other modules - but >> ultimately it depends on what you need to achieve. >> >> Hope this helps, >> >> Jon >> >> On Wednesday, June 22, 2016 at 3:10:03 PM UTC+1, Kenny Evitt wrote: >>> >>> 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/efbf67f2-6138-40de-828d-83c8310de101%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
