-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ansible 2.0 breaks "here" documents in shell scripts #12856
Comments
So, looking through the code, it looks a possible source of the problem is the parsing code in
Any preferences? |
Hi @larsks, in 2.0 you can actually use |
You mean, put code in that would remap |
This commit addresses ansible#12856, in which shell scripts passed to the `shell` module are corrupted to the split-and-rejoin approach taken in `lib/anslibe/parsing/splitter.py`. This commit modifies the behavior of `parse_kv` such that if there are no keyword arguments the raw arguments are returned verbatim, rather than going through the split-and-rejoin process.
@jimi-c, take a look at the PR I just submitted. This is a two-line change that implements the second option from my earlier comment: if there are no keyword arguments discovered, just return the raw string. With this change in place, this works just fine:
|
@larsks no, only command/shell/script would support it. Here's the working patch I have: diff --git a/lib/ansible/playbook/task.py b/lib/ansible/playbook/task.py index b66c331..3527cee 100644 --- a/lib/ansible/playbook/task.py +++ b/lib/ansible/playbook/task.py @@ -171,6 +171,15 @@ class Task(Base, Conditional, Taggable, Become): args_parser = ModuleArgsParser(task_ds=ds) (action, args, delegate_to) = args_parser.parse() + # the command/shell/script modules used to support the `cmd` arg, + # which corresponds to what we now call _raw_params, so move that + # value over to _raw_params (assuming it is empty) + if action in ('command', 'shell', 'script'): + if 'cmd' in args: + if args.get('_raw_params', '') != '': + raise AnsibleError("The 'cmd' argument cannot be used when other raw parameters are specified. Please put everything in one or the other place.", obj=ds) + args['_raw_params'] = args.pop('cmd') + new_ds['action'] = action new_ds['args'] = args new_ds['delegate_to'] = delegate_to |
I am a little more comfortable with my solution, because it doesn't require special-casing specific modules in |
We already filter out things which may try to populate _raw_params to a subset of modules. |
Huh. I didn't know that. I think my solution is still more obvious to someone using Ansible (you want a shell scripts? Here's your shell script.), but I guess either solution solves my immediate problem. |
Yep, I'm going to merge in my fix, as it follows the pattern in the code we already have. |
Closing This TicketHi! We believe the above commit should resolve this problem for you. This will also be included in the next major release. If you continue seeing any problems related to this issue, or if you have any further questions, please let us know by stopping by one of the two mailing lists, as appropriate:
Because this project is very active, we're unlikely to see comments made on closed tickets, but the mailing list is a great way to ask questions, or post if you don't think this particular issue is resolved. Thank you! |
At some point, ansible grew a hidden argument to shell/command tasks, the 'cmd' argument. History found at ansible/ansible#12856 Our project is making use of the cmd argument so that our shell bits do not get jinjad, so that we can use a here doc in the command. Unfortunately this was tripping up various tests in ansible-lint, and we had to ignore the files, which let other errors creep in. Thus this change adds the type of syntax we use to the test yaml files and updates the tests to propery handle them. Signed-off-by: Jesse Keating <jkeating@j2solutions.net>
At some point, ansible grew a hidden argument to shell/command tasks, the 'cmd' argument. History found at ansible/ansible#12856 Our project is making use of the cmd argument so that our shell bits do not get jinjad, so that we can use a here doc in the command. Unfortunately this was tripping up various tests in ansible-lint, and we had to ignore the files, which let other errors creep in. Thus this change adds the type of syntax we use to the test yaml files and updates the tests to propery handle them. Signed-off-by: Jesse Keating <jkeating@j2solutions.net>
At some point, ansible grew a hidden argument to shell/command tasks, the 'cmd' argument. History found at ansible/ansible#12856 Our project is making use of the cmd argument so that our shell bits do not get jinjad, so that we can use a here doc in the command. Unfortunately this was tripping up various tests in ansible-lint, and we had to ignore the files, which let other errors creep in. Thus this change adds the type of syntax we use to the test yaml files and updates the tests to propery handle them. Signed-off-by: Jesse Keating <jkeating@j2solutions.net> Conflicts: lib/ansiblelint/rules/CommandsInsteadOfArgumentsRule.py lib/ansiblelint/rules/CommandsInsteadOfModulesRule.py lib/ansiblelint/rules/EnvVarsInCommandRule.py lib/ansiblelint/rules/UseCommandInsteadOfShellRule.py test/command-check-success.yml test/command-instead-of-shell-success.yml test/env-vars-in-command-success.yml
At some point, ansible grew a hidden argument to shell/command tasks, the 'cmd' argument. History found at ansible/ansible#12856 Our project is making use of the cmd argument so that our shell bits do not get jinjad, so that we can use a here doc in the command. Unfortunately this was tripping up various tests in ansible-lint, and we had to ignore the files, which let other errors creep in. Thus this change adds the type of syntax we use to the test yaml files and updates the tests to propery handle them. Signed-off-by: Jesse Keating <jkeating@j2solutions.net>
At some point, ansible grew a hidden argument to shell/command tasks, the 'cmd' argument. History found at ansible/ansible#12856 Our project is making use of the cmd argument so that our shell bits do not get jinjad, so that we can use a here doc in the command. Unfortunately this was tripping up various tests in ansible-lint, and we had to ignore the files, which let other errors creep in. Thus this change adds the type of syntax we use to the test yaml files and updates the tests to propery handle them. Signed-off-by: Jesse Keating <jkeating@j2solutions.net> Conflicts: lib/ansiblelint/rules/CommandsInsteadOfArgumentsRule.py lib/ansiblelint/rules/CommandsInsteadOfModulesRule.py lib/ansiblelint/rules/EnvVarsInCommandRule.py lib/ansiblelint/rules/UseCommandInsteadOfShellRule.py test/command-check-success.yml test/command-instead-of-shell-success.yml test/env-vars-in-command-success.yml Conflicts: lib/ansiblelint/rules/CommandsInsteadOfModulesRule.py
I wanted to embed a "here" document (e.g.
cat <<EOF ...
) in ashell:
script in my playbook, like this:In 1.9.4, this breaks because the magic processing that looks for
module arguments in the command string resulted in the following
script:
Note the extra space (
) at the beginning of every line, which
breaks shell parsing. It was possible to fix this by passing the
script directly to the
cmd
parameter, which would bypass the magic"look for arguments" processing:
This worked great. But then Ansible 2.0 came along, and the above
fails with:
And without the
cmd:
parameter, it fails the same was as in 1.9.4.The text was updated successfully, but these errors were encountered: