Python Fabric 和 Amazon EC2:询问 Sudo 密码

发布于 2024-12-04 05:06:12 字数 1010 浏览 1 评论 0 原文

您知道,在 EC2 上,没有与“ubuntu”用户关联的密码。使用以下几行,如果我尝试运行:

fabdevelopment install_dir

我得到:

[ec2-46-51-132-252.eu-west-1.compute.amazonaws.com] sudo: chown -R webadmin:webadmin /var /万维网 [ec2-46-51-132-252.eu-west-1.compute.amazonaws.com] 登录密码:

我尝试将 shell=False 添加到 sudo 方法(根据 我可以阻止 Fabric 提示我输入密码吗? sudo 密码?),但它不会改变任何东西

有什么想法吗?多谢 !

def development():
    env.envname = 'development'
    env.user = 'ubuntu'
    env.group = 'ubuntu'
    env.chuser = 'webadmin'
    env.chgroup = 'webadmin'
    env.hosts = ['ec2-***.eu-west-1.compute.amazonaws.com']
    env.envname_abriev = 'dev'
    env.key_filename = '/home/xx/.ssh/xx.pem'

    env.postgresql_version = '9.0'

def install_dir():
    if not exists('/var/www'):
        sudo('mkdir /var/www')
    sudo('chown -R %s:%s /var/www' % (env.chuser, env.chgroup))

You know that on EC2, there is no password associated with "ubuntu" user. With the following lines, if I try to run :

fab development install_dir

I get :

[ec2-46-51-132-252.eu-west-1.compute.amazonaws.com] sudo: chown -R webadmin:webadmin /var/www
[ec2-46-51-132-252.eu-west-1.compute.amazonaws.com] Login password:

I tried to add shell=False to sudo method (according to Can I prevent fabric from prompting me for a sudo password?), but it doesn't change anything

Any idea ? Thanks a lot !

def development():
    env.envname = 'development'
    env.user = 'ubuntu'
    env.group = 'ubuntu'
    env.chuser = 'webadmin'
    env.chgroup = 'webadmin'
    env.hosts = ['ec2-***.eu-west-1.compute.amazonaws.com']
    env.envname_abriev = 'dev'
    env.key_filename = '/home/xx/.ssh/xx.pem'

    env.postgresql_version = '9.0'

def install_dir():
    if not exists('/var/www'):
        sudo('mkdir /var/www')
    sudo('chown -R %s:%s /var/www' % (env.chuser, env.chgroup))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独难免 2024-12-11 05:06:12

从 aws 下载(或创建)密钥对文件,如下所示从突出显示的部分下载密钥对

创建一个名为 fabfile.py 的文件
并按如下方式设置其内容:

from fabric.context_managers import cd
from fabric.operations import sudo
from fabric.api import run, env
import os

HOME = os.getenv('HOME')

env.user = 'ubuntu'
env.hosts = ['PUBLICDNS.ap-southeast-1.compute.amazonaws.com','ANOTHERSERVER.compute.amazonaws.com'] #can add multiple instances
env.key_filename = [
'%s/<your-keypair-file>.pem'%HOME
     ] #assuming keypair file is located in HOME

#example code we want to run on remote machine
def update():
    with cd('/var/www'):
            sudo('svn update')
                 with cd ('/var/www/cache'):
                       run('rm -rf *')
    sudo('service lighttpd restart')

要运行该文件,请在终端中键入 fab update。

Download (or create) a keypair file from aws as shown belowDownload keypair from the highlighted section

Create a file called fabfile.py
and set its contents as follows:

from fabric.context_managers import cd
from fabric.operations import sudo
from fabric.api import run, env
import os

HOME = os.getenv('HOME')

env.user = 'ubuntu'
env.hosts = ['PUBLICDNS.ap-southeast-1.compute.amazonaws.com','ANOTHERSERVER.compute.amazonaws.com'] #can add multiple instances
env.key_filename = [
'%s/<your-keypair-file>.pem'%HOME
     ] #assuming keypair file is located in HOME

#example code we want to run on remote machine
def update():
    with cd('/var/www'):
            sudo('svn update')
                 with cd ('/var/www/cache'):
                       run('rm -rf *')
    sudo('service lighttpd restart')

To run the file, type fab update in the terminal.

国际总奸 2024-12-11 05:06:12

您需要在运行 fab 命令时指定与您的 EC2 实例关联的密钥对文件名。

用法: fab [options] [:arg1,arg2=val2,host=foo,hosts='h1;h2',...] ...

选项:

-R ROLES, --roles=ROLES
                    comma-separated list of roles to operate on

-i KEY_FILENAME       path to SSH private key file. May be repeated.

You need to specify keypair file name associated with your EC2 instance while running fab command.

Usage: fab [options] <command>[:arg1,arg2=val2,host=foo,hosts='h1;h2',...] ...

Options:

-R ROLES, --roles=ROLES
                    comma-separated list of roles to operate on

-i KEY_FILENAME       path to SSH private key file. May be repeated.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文