Git Product home page Git Product logo

Comments (14)

matrixise avatar matrixise commented on September 22, 2024 1

I use the root user to connect via SSH.

fab check_user
Executing task 'check_user'
res: 'could not change directory to "/root"\r\n1'
True

Done.

the check_user task is a call to pg_user_exists(username), it's my modified function of postgres.user_exists(username)

def pg_user_exists(name):
    with settings(hide('running', 'stdout', 'stderr', 'warnings'),
        warn_only=True):
        res = _run_as_pg('''psql -t -A -c "SELECT count(*) FROM pg_user WHERE usename='%(name)s';"''' % locals())

    print "res: %r" % (res,)
    return '1' in res

def check_user():
    print pg_user_exists(DATABASE_OWNER)

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

Can you reproduce the issue? What is the exact output of the psql command? Maybe you can add a print repr(res) before the return (res == "1") line to understand what happens...

from fabtools.

 avatar commented on September 22, 2024

sure I've done that and reproduced it. printed the command output and the function output side to side.
The output is "1" as expected when the user is already created. But the function still return False, even if you add " echo | psql ..." at the beginning. This is why I was talking about gremlins, or whatever invisble characters mixed in the output.
Whereas ("1" in res) works like a charm for the same situation.

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

That's weird.

What version of fabric are you using?

Does return str(res) == "1" work?

from fabtools.

 avatar commented on September 22, 2024

No, it returns "None"

and now (after a vagrant destroy) even my fix does not work
I just got back to the lower level functions

if not fabtools.postgres.user_exists(env.user):
    fabtools.postgres.create_user(env.user, env.pgpass)

And unexpectedly, it works very well (??)

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

Problem solved, then? :)

from fabtools.

 avatar commented on September 22, 2024

On va dire que oui...

from fabtools.

danfairs avatar danfairs commented on September 22, 2024

Sorry to comment on a closed issue, but this bit me too. I dug a bit, and found the following:

-> return (res == "1")
(Pdb) print res
/bin/bash: /root/.bash_profile: Permission denied
could not change directory to "/root"
1

So - we're getting some error text at the start.

I don't know why this is appearing - it happens on a Ubuntu 10.04 LTS Linode VM, but not a local VMWare one(!). I worked around it by splitting into lines and looking at the last one (see my rough-and-ready fork). It's a weird one.

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

Thanks for your comment! This is weird. I'll try to dig into this some more.

from fabtools.

danfairs avatar danfairs commented on September 22, 2024

FTR, I still get this on a stock Ubuntu 12.04 LTS, with the latest fabtools. My workaround is to simply chmod a+rx /root - not ideal, but it works, and I don't particularly care if everyone can read /root.

My hunch is that this is happening because the postgres commands run as the 'postgres' user, and this typically doesn't have sudo access; and something, somewhere, is expecting to be able to source root's shell stuff as that user.

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

Not sure why it's trying to read /root/.bash_profile... This file does not exist on my Ubuntu VMs. Does it exist on the VMs where you saw the problem?

What's the output of "getent passwd postgres"?

What's the contents of the /etc/sudoers file?

Any other differences between VMs exhibiting the problem and those who don't?

I pushed an attempt at fixing the problem, running commands using "shell=False". Does it work for you?

from fabtools.

ronnix avatar ronnix commented on September 22, 2024

You should probably avoid directly connecting as root on your server, and I would even recommend disabling it altogether by adding PermitRootLogin no to /etc/ssh/sshd_config.

I think the problem comes from the fact that, when running a command as another user with sudo, fabric does not change the HOME environment variable, which causes the spurious message in the stdout. Maybe setting the HOME var in _run_as_pg will be able to fix the issue.

from fabtools.

tony avatar tony commented on September 22, 2024

You should probably avoid directly connecting as root on your server, and I would even recommend disabling it altogether by adding PermitRootLogin no to /etc/ssh/sshd_config.

That's true

But it's not a solution. root/sudo shouldn't be encumbered by permission issues

Ended up doing #4 (comment). That is hacky, but in the end, I'm using fabtools for convenience and just getting stuff deployed. I'm not a full-time devops person 😄

from fabtools.

agamm avatar agamm commented on September 22, 2024

Any elegant solution yet?

from fabtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.