【问题标题】:Autoscaling with AWS instances using Ansible-Pull with Master and slave Configuration使用带有主从配置的 Ansible-Pull 对 AWS 实例进行自动扩展
【发布时间】:2017-03-07 22:43:08
【问题描述】:

我目前正在使用 AWS 实例,并且希望仅使用 Ansible 将当前在 AWS 主节点上运行的所有配置传输到多个 AWS 从节点。从节点可以是 2 个或 3 个或更多。 ansible-pull 模型是否可以在从节点的“利用率”下降或上升时自动扩展 AWS 实例?

如何分配节点的 AWS 集群?

【问题讨论】:

    标签: amazon-web-services ansible ansible-pull


    【解决方案1】:

    虽然不是直接回答,但在配置自动缩放的情况下,我使用Bootstrap Pattern

    将 git 存储库和 ansible-vault 的密钥放在 S3 上(由实例的 IAM 角色进行身份验证),并将 playbooks 放在 git 存储库中。

    EC2实例的用户数据为pip install ansibleget secret key from S3get playbook from git repositoryexecute ansible-playbook

    如果有EC2实例的角色,可以拆分S3目录和git路径。

    自引导机制使自动缩放过程更加简单。

    Update01:示例

    EC2 用户数据样本(尚未测试,作为图像):

    #!/bin/bash
    
    yum update -y
    pip install -y ansible
    
    aws s3 cp s3://mybucket/web/git_secret_key /root/.ssh/git_secret_key
    chmod 600 /root/.ssh/git_secret_key
    
    aws s3 cp s3://mybucket/web/config /root/.ssh/config
    chmod 600 /root/.ssh/config
    
    aws s3 cp s3://mybucket/web/ansible_vault_secret_key /root/ansible_vault_secret_key
    
    git clone git://github.com/foo/playbook.git
    
    ansible-playbook -i playbook/inventory/web playbook/web.yml --vault-password-file /root/ansible_vault_secret_key
    

    s3://mybucket/web/config 示例:

    Host github-bootstrap
      User git
      Port 22
      HostName github.com
      IdentityFile /root/.ssh/git_secret_key
      TCPKeepAlive yes
      IdentitiesOnly yes
    

    Update02:最简单的版本。 (没有 S3/ansible-vault)

    EC2 用户数据样本(尚未测试,作为图像):

    #!/bin/bash
    
    yum update -y
    pip install -y ansible
    
    echo "YOUR GIT SECRET KEY" > /root/.ssh/git_secret_key
    chmod 600 /root/.ssh/git_secret_key
    
    cat << EOT > /root/.ssh/config
    Host github-bootstrap
      User git
      Port 22
      HostName github.com
      IdentityFile /root/.ssh/git_secret_key
      TCPKeepAlive yes
      IdentitiesOnly yes
    EOT
    chmod 600 /root/.ssh/config
    
    git clone git://github.com/foo/playbook.git
    
    ansible-playbook -i playbook/inventory/web playbook/web.yml
    

    【讨论】:

    • 这看起来对我有用。是否必须在 S3 上创建快照并使用 Ansible-vault ?
    • 如果你的剧本没有秘密数据,你不必为此使用 ansible-vault 和密钥。而且,如果您的 git 存储库是安全的,您不必将 git 存储库的密钥放在 S3 上。在最简单的情况下,您不必使用 S3。我认为在所有情况下都不需要快照,但是您需要将主节点的状态复制到从节点吗?如果要将主节点的状态复制到从节点,则需要传输过程或快照。
    • 我有一个私有的 github 存储库,其中我有一些文件,其中包含我需要在从站上应用的基本配置。那么,当新的从属实例出现自动扩展功能(Ansible Pull)时,AWS 从属会自动捕获文件或从 github 存储库分配配置吗?还是我需要为那些设置 cron 作业?
    • 请查看更新的示例。 AWS Slaves 通过 EC2 设置的用户数据执行 self git clone 以捕获配置。
    • 这是自动完成的吗?还是每次新实例出现时我都需要运行那些shell脚本吗?如果是,那么没有理由进行 ansible-pull..
    猜你喜欢
    • 2014-05-28
    • 2017-11-14
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 2022-11-07
    相关资源
    最近更新 更多