Comments (14)
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.
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.
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.
That's weird.
What version of fabric are you using?
Does return str(res) == "1"
work?
from fabtools.
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.
Problem solved, then? :)
from fabtools.
On va dire que oui...
from fabtools.
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.
Thanks for your comment! This is weird. I'll try to dig into this some more.
from fabtools.
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.
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.
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.
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.
Any elegant solution yet?
from fabtools.
Related Issues (20)
- centos 7 support - fabtools.require.rpm.repository('epel') fails
- feature request: with fabtools.python.version(3.4): do smth HOT 2
- install_pip or package fails on centos 7 with sudo config setting <Defaults requiretty> HOT 3
- fabtools.require.python.virtualenv() is installing wheel from sources?
- Travis Tests?
- require tries to create home dir even if create_home is False
- mysql.query does not allow the use of --defaults-file
- Redis v3.2.x require fails because of binary rename
- fix md5sum in files.py
- require.oracle_jdk.installed fails due to change in Oracle download URL
- Issue while installing fabtools3 inside a container. HOT 1
- Fabric v2 support HOT 3
- sudo will fail when checking Postgres user
- systemd and supervisor processes can freeze due to pager HOT 1
- Update setup.py to pull fabric3 for Python 3
- `fabtools.files.mode` does not work properly with character expansion HOT 3
- `fabtools.require.files.file` mode type HOT 1
- error on add_ssh_public_key HOT 2
- how pytest run ?
- Fix simple typo: occured -> occurred
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fabtools.