Skip to content
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

[2.0rc3] Fetch module cannot deal with multiline argument #13630

Closed
feliksik opened this issue Dec 22, 2015 · 6 comments
Closed

[2.0rc3] Fetch module cannot deal with multiline argument #13630

feliksik opened this issue Dec 22, 2015 · 6 comments
Labels
bug This issue/PR relates to a bug.
Milestone

Comments

@feliksik
Copy link
Contributor

If I use > for multiline strings in the fetch module, this goes fine; according to yaml spec, the newlines are stripped.

- name: save public keys to local system
  fetch: >
    src=/home/{{ssh_user}}/{{ssh_key_file}}.pub
    dest=secret/{{environment_prefix}}/hosts/{{inventory_hostname}}/home/{{ssh_user}}/{{ssh_key_file}}.pub
    fail_on_missing=yes
    flat=yes

But with ^ it breaks (the yaml resulting string then contains \n). The point is: this worked with Ansible 1.9. I think it was an explicit goal to be backwards compatible, so therefore I report it.

- name: save public keys to local system
  fetch: >
    src=/home/{{ssh_user}}/{{ssh_key_file}}.pub
    dest=secret/{{environment_prefix}}/hosts/{{inventory_hostname}}/home/{{ssh_user}}/{{ssh_key_file}}.pub
    fail_on_missing=yes
    flat=yes

outputs:

ERROR! this task 'fetch' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta

The error appears to have been in '/home/eric/projects/heater/roles/ssh_host/tasks/main.yml': line 7, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

# - install keys on relevant host
- name: save public keys to local system
  ^ here

@feliksik feliksik changed the title [2.0] Fetch module cannot deal with multiline argument [2.0rc3] Fetch module cannot deal with multiline argument Dec 22, 2015
@jimi-c jimi-c added this to the v2 milestone Dec 31, 2015
@edrozenberg
Copy link
Contributor

Having the same issue with the unarchive module. Ansible release 2.0.0.2

For example the following task:

# Unzip the Postgres PrefPane to the Mac PrefPanes system directory
- name: unzip postgres prefpane to system prefpane dir
  unarchive: >
    src={{ ppfile_result.stdout | regex_replace(' ', '\ ') }}
    dest={{ macprefpane_dir }}
    copy=no
    owner=root
    group=admin
    mode=0644
  become: yes
  become_method: sudo
  when: >
    (ppdir_result.stat.isdir is undefined) or
    (ppver_result.stdout != ppfilever_result.stdout)

Causes the following error:

TASK [desktop/mac : include] ***************************************************
fatal: [zebra]: FAILED! => {"failed": true, "reason": "ERROR! this task 'unarchive' has extra params, which is only allowed in the following modules: command, shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta\n\nThe error appears to have been in '/Users/eduardr/Developer/Work/Ansible/roles/desktop/mac/tasks/pgsql.yaml': line 158, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# Unzip the Postgres PrefPane to the Mac PrefPanes system directory\n- name: unzip postgres prefpane to system prefpane dir\n  ^ here\n"}

PLAY RECAP *********************************************************************
zebra                      : ok=57   changed=6    unreachable=0    failed=1   

Also noticed the error output from Ansible now contains literal "\n" characters that are not properly interpreted by the Mac terminal, so the error messages display the error text all jumbled together.

@edrozenberg
Copy link
Contributor

@jimi-c I'm still having the same problem with ansible 2.0.1.0.

Not sure why reports of this aren't widespread though, maybe few people are using this multi-line style?

And don't know why unarchive in particular has this issue - I use the same multi-line style with many other modules with no problem.

@edrozenberg
Copy link
Contributor

@jimi-c Some further info after digging a bit more:

  • Have had the issue with unarchive and file modules
  • Issue workaround is to quote args that have {{ }} parameters. For example this doesn't work:
- name: unzip postgres prefpane to system prefpane dir
  unarchive: >
    src={{ ppfile_result.stdout | regex_replace(' ', '\ ') }}
    dest={{ macprefpane_dir }}

Adding quotes makes it work:

- name: unzip postgres prefpane to system prefpane dir
  unarchive: >
    src="{{ ppfile_result.stdout | regex_replace(' ', '\ ') }}"
    dest="{{ macprefpane_dir }}"

jimi-c added a commit that referenced this issue Mar 28, 2016
@jimi-c
Copy link
Member

jimi-c commented Mar 28, 2016

@feliksik it looks like we fixed your issue here already, at least what I'm seeing in devel and stable-2.0.

@edrozenberg the patch above appears to resolve your issue, just waiting for tests to pass to confirm it doesn't introduce any other bugs.

@jimi-c jimi-c closed this as completed in f2713f7 Mar 28, 2016
jimi-c added a commit that referenced this issue Mar 28, 2016
Previously, split_args() was not taking print/block/comment depth into account
when splitting things, meaning that if there was a quote character inside an
un-quoted variable (ie. {{ foo | some_filter(' ') }}), it was incorrectly
splitting on the quotes instead of continuing to append to the previous param.

Fixes #13630
jimi-c added a commit that referenced this issue Mar 28, 2016
@jimi-c
Copy link
Member

jimi-c commented Mar 28, 2016

Merged the above into both devel and stable-2.0, so this will be included with 2.0.2.

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!

@hrstoyanov
Copy link

Thank you. It works now.

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

5 participants