1

Using fabric if I echo to sudoers file for second time the file got corrupted works fine for first echo. What could be the reason?

First echo:

sudo('echo "django    ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers')

Second echo:

sudo('echo "celery    ALL(www-data) NOPASSWD: /usr/bin/unoconv" | sudo tee -a /etc/sudoers')

After second echo command and when trying to do sudo I am getting parse error and I am not able to recover the sudoers file again, I have to create a new instance unfortunately:

>>> /etc/sudoers: syntax error near line 28 <<<
sudo: parse error in /etc/sudoers near line 28
sudo: no valid sudoers sources found, quitting

There is no syntax issue as such in second command because if I type it manually using visudo it works fine. And I don't think that its fabric related issue. Fabric is just executing commands on the remote server.

  • 1
    as posted, the line in your second echo is wrong; I tried manually adding django ALL=(ALL:ALL) ALL celery ALL(www-data) NOPASSWD: /usr/bin/unoconv to my sudoers using visudo and I also get a syntax error. I think you need = before (www-data), but in any case there is an error there. If as you say typing it manually works, I'm pretty sure what you're typing is different. – roadmr Aug 6 '14 at 20:45
  • @roadmr can you point out whats wrong in the second echo command? I guess it might be I am using 4 spaces instead of a tab in between django and ALL ?? – Aamir Adnan Aug 6 '14 at 20:47
  • 1
    A tip to validate sudo syntax without destroying your sudoers file: echo 'blah blah' | visudo -f - -c. This will at least tell you if the line looks OK or has errors, without touching your sudoers file. – roadmr Aug 6 '14 at 20:47
  • Oops sorry. I missed the = sign. But as you are saying it is still throwing error then what would be the reason? Do you see any other issue? I see in my sudoers file I have = sign ALL=(www-data)so its a good catch from your side but everything else is same. – Aamir Adnan Aug 6 '14 at 20:51
  • it's not the spaces, I'm pretty sure it's the lack of =. Give it a try :) – roadmr Aug 6 '14 at 20:52
3

As posted, the line in your second echo is wrong; I tried manually adding

django ALL=(ALL:ALL) ALL 
celery ALL(www-data) NOPASSWD: /usr/bin/unoconv 

to my sudoers using visudo and I also get a syntax error. You need = before (www-data) in the second line.

A tip to validate sudo syntax without destroying your sudoers file: echo 'blah blah' | visudo -f - -c. This will at least tell you if the line looks OK or has errors, without touching your sudoers file.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.