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

Ansible 1.8.2 shell action doesn't handle ">" redirect correctly #9791

Closed
mikesac opened this issue Dec 12, 2014 · 9 comments
Closed

Ansible 1.8.2 shell action doesn't handle ">" redirect correctly #9791

mikesac opened this issue Dec 12, 2014 · 9 comments
Labels
bug This issue/PR relates to a bug. needs_info This issue requires further information. Please answer any outstanding questions. P2 Priority 2 - Issue Blocks Release

Comments

@mikesac
Copy link

mikesac commented Dec 12, 2014

Issue Type:Bug Report
Ansible Version:1.8.2
Environment: Ubuntu 12.04 (vagrant box)
Summary:

it seems that "shell" action has some issue handling stdout redirect.

my action is (I've tried any kind of quoting)

 - name : Dump previous database data - mysql_56
   shell: "mysqldump -u{{ item.value.user }} -p{{ item.value.pass }} {{ item.value.name }} > {{ deploy_path }}/db/{{ item.value.name }}-{{ nowdate.stdout }}.sql"
   with_dict: db

but it always fails with error:

stderr: mysqldump: Couldn't find table: ">"

simply rolling-back ansible to 1.7.2 made the action back to work as usual.

This seems to be affecting any "shell" action with redirect within.

Steps To Reproduce: simply run a playbook with a shell action using a ">" redirect
@michalgasek
Copy link

This doesn't fix Ansible's problem but it might fix your problem.
http://dev.mysql.com/doc/refman/5.6/en/mysqldump.html#option_mysqldump_result-file

And then you can use command module instead of shell with redirect.
I just avoid shell module whenever I can.

@abadger abadger added P2 Priority 2 - Issue Blocks Release bug_report labels Dec 12, 2014
@abadger
Copy link
Contributor

abadger commented Dec 12, 2014

I'm not able to reproduce with either 1.8.1, devel, or the 1.8.2 tag in the git repo using the following playbook:

---
- hosts: localhost
  vars:
    dir: '/var/tmp'
    echo_dict:
      one:
        msg:
          'blue'
        file:
          'redirect3'
  tasks:
    - name: redirection3
      shell: "echo {{ item.value.msg }} > {{ dir }}/{{ item.value.file }}"
      with_dict: echo_dict

Are you able to reproduce with that? Do you have a simpler play that shows the problem or are you able to show us enough of your mysqldump play to reproduce it?

@abadger abadger added the needs_info This issue requires further information. Please answer any outstanding questions. label Dec 12, 2014
@Jmainguy
Copy link
Contributor

It should also be noted, the mysql_db module offers dump as an option, while has nothing to do with this bug report, would likely be the best module to use for the task above.

@mikesac
Copy link
Author

mikesac commented Dec 12, 2014

Thanks abadger, you sample look the same as mine under all relevant aspects, i'll try to re-create a vagrant box with latest 1.8.2 version asap and let you know. ansible was installed via PIP, don't know if this may differ from a clean check out in any way.

Jmainguy, mysql_db has a big limit, it works just with mysql versions up to 5.5 while I have to cover 5.6 as well. Morover dump option doesn't allow tables filtering but just full db dump.

@Jmainguy
Copy link
Contributor

oh, I was not aware it stopped working with 5.5, I will have to check into that. Ty sir

@mikesac
Copy link
Author

mikesac commented Dec 12, 2014

Ok guys, I've just re-upgraded the very same box to Ansible 1.8.2 via PIP and it seems that now both @abadger sample and my playbook are executing correctly.

The only possible scenario I can though about is that my first installation was somehow corrupted (I was upgrading from an older 1.4.x version, while now the starting point was 1.7.2)

Upgrade procedure (both this one as the previous one) completed with an error, but it seems that Ansible got updated properly.

  Found existing installation: pycrypto 2.4.1
    Uninstalling pycrypto:
      Removing file or directory /usr/share/pyshared/pycrypto-2.4.1.egg-info
      Successfully uninstalled pycrypto
  Running setup.py install for pycrypto
    Running command /usr/bin/python -c "import setuptools;__file__='/root/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-e3pIAW-record/install-record.txt
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: No module named setuptools
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/root/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-e3pIAW-record/install-record.txt:
    Traceback (most recent call last):

  File "<string>", line 1, in <module>

ImportError: No module named setuptools

----------------------------------------
  Rolling back uninstall of pycrypto
  Replacing /usr/share/pyshared/pycrypto-2.4.1.egg-info
Command /usr/bin/python -c "import setuptools;__file__='/root/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-e3pIAW-record/install-record.txt failed with error code 1
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 126, in main
    self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 228, in run
    requirement_set.install(install_options, global_options)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1093, in install
    requirement.install(install_options, global_options)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 566, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 255, in call_subprocess
    % (command_desc, proc.returncode))
InstallationError: Command /usr/bin/python -c "import setuptools;__file__='/root/build/pycrypto/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-e3pIAW-record/install-record.txt failed with error code 1


root@packer-virtualbox:~# ansible --version
ansible 1.8.2

I do not know if this can be relevant or not but surely shell module has no problem at all. :)

Thanks everyone for your support, and sorry for the fake alarm, I think this issue can be closed.

@michalgasek thanks for your hint, I'll try to move my shell action to command with the additional option you suggested asap

@mpdehaan
Copy link
Contributor

Shell module shouldn't have any issues with ">" FWIW. Not sure why you are avoiding, but it is a good idea to use shell if you are worried about someone setting variables and making sure they don't stick something fishy in there, etc.

@michalgasek
Copy link

@mpdehaan "avoid" is a wrong word here.
I do use shell only when command is not sufficient and can't do the job (as docs of shell module suggest in notes). In this case command gets things done.

@jimi-c
Copy link
Member

jimi-c commented Jun 29, 2015

Hi all, looking back through old issues and it appears this was resolved but never closed, so closing it now.

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!

@jimi-c jimi-c closed this as completed Jun 29, 2015
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 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. needs_info This issue requires further information. Please answer any outstanding questions. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

7 participants