一个帮助程序,将为您设置一个远程服务器

server-automation-setup的Python项目详细描述


服务器自动化设置

一个帮助程序,将为您设置一个远程服务器

目录


安装

PIP

Server Automation Setup可通过pip安装

python3 -m pip install server-automation-setup

手动

或者,如果您喜欢冒险,可以从github下载安装脚本并运行以下命令。在

^{pr2}$

NOTE: Be careful executing random files off the internet. Always inspect them first

一旦完成,您应该看到如下输出

Finished! Execute 'serverautomation --help' to get started!

依赖性

无论您选择哪个安装决定,我们的依赖项都已安装。 我们赖以正常运行的程序是

卸载

python3 -m pip uninstall server-automation-setup

怎么跑

运行安装脚本很容易。只需向它提供一个配置文件来加载,它就可以处理其他所有事情。在

serverautomation -f=yourfile.validextension

可用参数

-f, --file: Your configuration File.
    This must be a JSON or YAML file, unless the script explicitly gives you a file to run.
-v, --verbose: Tells the system to print out more details
-d, --debug: When enabled, we will still connect to the remote server, 
    but then we simply dump all the commands we would run to the terminal window for the user to see
-e, --onfail: How to handle failure. Options are (continue, die). Default is continue

服务器故障怎么办?

会发生的。某个原因导致某个安装脚本崩溃。服务器被弹出。其中一个外部脚本中断。等。 那么,在设置闪亮的新服务器时发生故障时会发生什么呢?当发生错误时,我们处理它(取决于^{}的设置)。无论^{}的状态如何,我们都将跟踪安装过程中失败的脚本。一旦我们完成运行,如果发现失败,我们将为您提供一个特殊的文件,您可以使用它来只执行失败的脚本。它看起来像这样

Server Setup completed with errors. To rerun failed scripts, execute the following command. serverautomation --file 127.0.0.1-20200420-202251

配置

配置文件可以JSONYAML格式提供。下面是这两种格式,并提供任何可用选项的文档

JSON

{
    "server_connection": {
        // Optional
        // This needs to be an ip address that is accessible from the box this is ran off of
        "ip_address": "127.0.0.1",
        // Optional
        // Either provide this or ip address. If you provide both, we will use the ip address. 
        "hostname": "some-host",
        // Optional
        // if not provided, we assume you want to ssh in as root.
        "ssh_user": "someuser",
        // Optional
        // if used, this needs to be the path to an ssh key, or if the file is in the same directory this can be the ssh key name directly
        "ssh_key": "id_rsa",
        // Optional
        // if an ssh_user is provided, you can provide an ssh password for that user
        "ssh_user_password": "somepassword",
        // Optional
        // If not provided, we will ask for it once
        "ssh_key_password": "somepassword",
        // Optional
        // The sudo password for the server. If not provided, we will ask for it
        "elevation_password": "somepassword"
    },
    "users": [
        {
            "username": "testuser",
            // This can be 
            // - An empty string or 'None' (both equate to None)
            // - Cleartext password
            // In all cases the password must be cleartext (you're using a config script to setup users. Deal with the security risk, or dont use it)
            "password": "",
            // The rest of these are optionals

            // Can either be full path or program name.
            "shell": "zsh",
            // Optional
            // The expected home directory location
            // If not provided (and not a system_user), we will simply let linux decide where to put you.
            // Usually by default this will be /home/username
            "home_directory": "/home/",
            // List of groups. If you only want it to be in its own group, leave this blank
            // The system will attempt to make sure that the user has sudo permissions if it is placed in
            // either sudo or wheel. The system will try to verify that either of those groups exist and have the appropriate permission
            // It is better to be sure you know what you want here, but we will try for you
            "groups": ["sudo"],
            // Optional
            // This is not case sensitive, but it does have to be a boolean T/F. If left blank, it will be considered false
            "system_user": "False",
            // Optional
            // If provided, we will copy an ssh key over to the server for you. If you want to just use the 
            // key provided, simply supply 'default' (not case sensitive). Otherwise, we will expect 
            // the name of the key you are looking for. If you do not provide a full path to it, we will 
            // check in the running user's .ssh directory, however that isn't the best idea. You should
            // really just provide a full path
            // NOTE! If the user is a system_user (ie, no login), this will be ignored
            "ssh_key": "default"
        }
    ],
    "dependencies": [
        // Optional
        // Experimental
        // We will attempt to install the dependencies in this list regardless of the distro of the box
        // we are on
        "someprogram1","someprogram2","someprogram3"
    ],
    // EXPIRAMENTAL!
    // Optional
    "server_configuration": {
        // Sets the hostname of the server to the provided hostname
        "hostname": "newhostname_for_server",
        // Tells the system to update the server. Not case sensitive. If present, this will be run before anything else
        "update": "True",
        // Tells the system to upgrade the server distro. Not case sensitive
        "upgrade": "True",
        // Tells the system to disconnect and restart the server on completion. This is the very last thing ran, if present
        "reboot_on_finish": "True",
        // Services that we need to enable for the server. We expect the service(s) to be installed already. If its not, you're on
        // your own. Don't set us up for failure. 
        "enabled_service": [
            "someprogram1",
            "someprogam2"
        ]
    },
    "configurations":[
        // Optional
        // A list of scripts to execute in order on the server box.
        // Make sure that the server has the software installed to execute the script language though
        // 
        // You can additionally provide params for the system to obey when executing the script provided. You can also provide 
        // params to the script itself. We will consume the params we expect and pass all the rest to the script
        // The following params are reserved for us (meaning, if they are provided, we will consume then and they will not be passed along). None of these are case sensitive
        // --runAs=whatever user you want the script to be run as
        // --local tells us that you want the script to be locally (on the hosting box) instead of remotely. Note, we assume by default the scripts are to be
        //         run remotely. 
        //
        // You can also provide params for your script here, and those are passed to your script as well
        //
        // We pass the following additional params to every script that is run locally
        // --host=whatever the server ip is that we just finished our setup on
        // --user=whatever the user is that we used when initiating our connection to the server
        // --password=whatever the user's password is.
        // --ssh_key=whatever the ssh key is that was used to connect to the server. Note this is only provided if we were provided one
        // --ssh_passphrase=whatever the passphrase is for the key. Note this is only provided if we are provided it
        "someFile1.py --runAs=root",
        "someFile2.pl --someparam=somevalue",
        "someFile3.sh"
    ]
}

YAML

server_connection:# Optional# This needs to be an ip address that is accessible from the box this is ran off ofip_address:127.0.0.1# Optional# Either provide this or ip address. If you provide both, we will use the ip address.hostname:some-host# Optional# if not provided, we assume you want to ssh in as root.ssh_user:someuser# Optional# if an ssh_user is provided, you can provide an ssh password for that userssh_user_password:"somepassword"# Optional# if used, this needs to be the path to an ssh key, or if the file is in the same directory this can be the ssh key name directlyssh_key:id_rsa# Optional# If not provided, we will ask for it oncessh_key_password:somepassword# Optional# The sudo password for the server. If not provided, we will ask for itelevation_password:somepasswordusers:-username:testuser# This can be # - An empty string or 'None' (both equate to None)# - Cleartext passwordpassword:''# The rest of these are optionals# Can either be full path or program name.shell:zsh# Optional# The expected home directory location# If not provided (and not a system_user), we will simply let linux decide where to put you.# Usually by default this will be /home/usernamehome_directory:"/home/"# List of groups. If you only want it to be in its own group, leave this blank# The system will attempt to make sure that the user has sudo permissions if it is placed in# either sudo or wheel. The system will try to verify that either of those groups exist and have the appropriate permission# It is better to be sure you know what you want here, but we will try for yougroups:-sudo-someothergroup1-someothergroup1# Optional# This is not case sensitive, but it does have to be a boolean T/F. If left blank, it will be considered Falsesystem_user:'False'# Optional# If provided, we will copy an ssh key over to the server for you. If you want to just use the # key provided, simply supply 'default' (not case sensitive). Otherwise, we will expect # the name of the key you are looking for. If you do not provide a full path to it, we will # check in the running user's .ssh directory, however that isn't the best idea. You should# really just provide a full path# NOTE! If the user is a system_user (ie, no login), this will be ignoredssh_key:default# Optionaldependencies:# We will attempt to install the dependencies in this list regardless of the distro of the box we are on-someprogram1-someprogram2-someprogram3server_configuration:# Sets the hostname of the server to the provided hostnamehostname:newhostname_for_server# Tells the system to update the server. Not case sensitive. If present, this will be run before anything elseupdate:'True'# Tells the system to upgrade the server distro. Not case sensitiveupgrade:'True'# Tells the system to disconnect and restart the server on completion. This is the very last thing ran, if presentreboot_on_finish:'True'# Services that we need to enable for the server. We expect the service(s) to be installed already. If its not, you're on# your own. Don't set us up for failure. enable_service:-someprogram1-someprogam2configurations:# Optional# A list of scripts to execute in order on the server box.# Make sure that the server has the software installed to execute the script language though# # You can additionally provide params for the system to obey when executing the script provided. You can also provide # params to the script itself. We will consume the params we expect and pass all the rest to the script# The following params are reserved for us (meaning, if they are provided, we will consume then and they will not be passed along). None of these are case sensitive# --runAs=whatever user you want the script to be run as# --local tells us that you want the script to be locally (on the hosting box) instead of remotely. Note, we assume by default the scripts are to be#         run remotely. ## You can also provide params for your script here, and those are passed to your script as well## We pass the following additional params to every script that is run locally# --host=whatever the server ip is that we just finished our setup on# --user=whatever the user is that we used when initiating our connection to the server# --password=whatever the user's password is.# --ssh_key=whatever the ssh key is that was used to connect to the server. Note this is only provided if we were provided one# --ssh_passphrase=whatever the passphrase is for the key. Note this is only provided if we are provided it-someFile1.py --runAs=root-someFile2.pl --someparam=somevalue-someFile3.sh

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java为什么会出现这些错误?表达式的非法开始   使用HttpUrlConnection的java测试URL仅适用于前面的www   在大数据集上使用kmeans的java堆外内存   查找Java RandomAccessFile如何以字符形式读取第n个字节   java Android从BroadcastReceiver获取标题和描述   java使用构造函数参数模拟嵌套类并测试方法   正在将Azure Blob项强制转换为Java文件对象   java并行运行testNG套件   java程序在运行时似乎没有进入   贬低Java规则引擎的优点和缺点   文本区域中的java中心文本   java JPA从多个表中选择错误   类Java问题使用类加载器重新加载代码   java如何在Spring非管理类上使用@Value   java(关闭)Gradle导入VS代码失败   java arraylist拆分(“空白”)并计算字数   Android/Java如何在单独的*中调用函数。java文件?   具有基本身份验证的java Apache Camel RSS模块   java为什么程序在出现溢出或下溢时不抛出异常