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

shell cat <<EOF command adding space in front of every line #39137

Closed
naisanza opened this issue Apr 23, 2018 · 2 comments
Closed

shell cat <<EOF command adding space in front of every line #39137

naisanza opened this issue Apr 23, 2018 · 2 comments

Comments

@naisanza
Copy link

@naisanza naisanza commented Apr 23, 2018

ISSUE TYPE
  • Bug
COMPONENT NAME

Ansible Module: shell

ANSIBLE VERSION
ansible 2.5.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
CONFIGURATION
No Changes
OS / ENVIRONMENT

Ubuntu 17.10.1

SUMMARY

I've changed the shell module to use executable: /bin/bash now

And using the multiline command. However, the resulting file has a space in front of every line?

  - name: Pycharm
    shell: |
      apps=/tmp/apps
      pycharm=pycharm.tgz
      if [ ! -d '/opt/pycharm' ]; then mkdir /opt/pycharm; fi
      if [ ! -f $apps/$pycharm ]; then
          wget -q -O $apps/$pycharm 'https://download-cf.jetbrains.com/python/pycharm-community-2018.1.tar.gz'
          tar zxf $apps/$pycharm -C /opt/pycharm
      else
          tar zxf $apps/$pycharm -C /opt
      fi
      ln -s /opt/pycharm/pycharm-community-2018.1/bin/pycharm.sh /usr/local/bin/pycharm
      cat > /usr/share/applications/pycharm.desktop << EOF
      [Desktop Entry]
      Encoding=UTF-8
      Name=Pycharm IDE
      Comment=The Smarter Way to Code
      Exec=/bin/sh "/opt/pycharm/pycharm-community-2018.1/bin/pycharm.sh"
      Icon=/opt/pycharm/pycharm-community-2018.1/bin/pycharm.png
      Categories=Application;Development;Python;IDE
      Version=1.0
      Type=Application
      Terminal=0
      EOF
    args:
      executable: /bin/bash

https://github.com/TheShellLand/antsable/blob/master/playbooks/ubuntu-readyup-17.x.yml#L245

/usr/share/applications/pycharm.desktop:

 [Desktop Entry]
 Encoding=UTF-8
 Name=Pycharm IDE
 Comment=The Smarter Way to Code
 Exec=/bin/sh "/opt/pycharm/pycharm-community-2018.1/bin/pycharm.sh"
 Icon=/opt/pycharm/pycharm-community-2018.1/bin/pycharm.png
 Categories=Application;Development;Python;IDE
 Version=1.0
 Type=Application
 Terminal=0
 EOF
^ extra space

Also, the EOF gets added in to the file as well

@ansibot

This comment has been minimized.

Copy link
Contributor

@ansibot ansibot commented Apr 23, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@Akasurde

This comment has been minimized.

Copy link
Member

@Akasurde Akasurde commented Apr 23, 2018

@naisanza You can use cmd argument for multiline command like -

---
- name: Test shell
  hosts: localhost
  gather_facts: no
  tasks:
    - name: Execute cat 
      shell:
        cmd: |
          cat > /tmp/a.txt << EOF
          This is a
          EOF
          echo "this is new line" >> /tmp/a.txt
      args:
        executable: /bin/zsh

Thanks very much for your interest in Ansible. It sincerely means a lot to us.

This appears to be a user question, and we'd like to direct these kinds of things to either the mailing list or the IRC channel.

If you can stop by there, we'd appreciate it. This allows us to keep the issue tracker for bugs, pull requests, RFEs and the like.

Thank you once again and we look forward to seeing you on the list or IRC. Thanks!

@Akasurde Akasurde closed this Apr 23, 2018
naisanza pushed a commit to TheShellLand/antsable that referenced this issue Apr 23, 2018
naisanza pushed a commit to TheShellLand/antsable that referenced this issue Apr 23, 2018
@sivel sivel removed the needs_triage label Apr 23, 2018
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.