Your issue is that one of your arguments contains a " and when shlex tries
to split the arguments as a list it fails to find the end ". E.g the value
of script you set is
script: "{{ role_path }}/files/portal.ps1 {{ dbuser }} {{
vault_win_password }}"
# when taking away Jinja2 this becomes
script: /some/path/files/portal.ps1 user foo20"
When trying to turn the string to a list of arguments ([portal.ps1",
"user", "foo20\""]), it fails to find the end quote for the password quote.
What you need to do is use the quote filter to automatically quote each
argument, e.g.
script: "{{ role_path }}/files/portal.ps1 {{ dbuser|quote }} {{
vault_win_password|quote }}"
# if you wanted to do it manually without the quote filter (please don't)
script: "{{ role_path }}/files/portal.ps1 '{{ dbuser }}' '{{
vault_win_password }}'"
# when taking away Jinja2 this become
script: /some/path/files/portal.ps1 "user" "foo20\""
This means each argument is quoted so shlex can split them into a list
without any issues.
You second issue also comes down to quotes, when interpreting this
script: "{{ role_path }}/files/file.ps1 {{ location }}"
# this is seen by Ansible as
script: /some/path/files/portal.ps1 C:\Program Files (x86)\bar
When running in Windows, it sees this as 3 different arguments;
["C:\Program", "Files", "(x86)\bar"] as it is not quoted. PowerShell makes
this a bit more complex, the 3rd argument (x86)\bar, PowerShell see the
brackets and things the value inside is a command and so tries to run it
which in turn leads to the error x86 is not recognized as the name of a
cmdlet, function... The fix for this is the same as your previous issue,
use the quote filter to quote the values
script: "{{ role_path }}/files/file.ps1 {{ location }}"
# without using the quote filter this is how it can be done (once again
please don't this is just to illustrate how it could be done)
script: "{{ role_path }}/files/file.ps1 \"{{ location }}\""
# or
script: "{{ role_path }}/files/file.ps1 '{{ location }}'"
# this is seen by Ansible as
script: /some/path/files/portal.ps1 "C:\Program Files (x86)\bar"
Now because the path is quoted, it is seen as 1 argument instead of 3.
Thanks
Jordan
--
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/77d3df4a-596b-4bcc-a460-8a13f28a5d4a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.