【发布时间】:2017-03-07 22:43:08
【问题描述】:
我目前正在使用 AWS 实例,并且希望仅使用 Ansible 将当前在 AWS 主节点上运行的所有配置传输到多个 AWS 从节点。从节点可以是 2 个或 3 个或更多。 ansible-pull 模型是否可以在从节点的“利用率”下降或上升时自动扩展 AWS 实例?
如何分配节点的 AWS 集群?
【问题讨论】:
标签: amazon-web-services ansible ansible-pull
我目前正在使用 AWS 实例,并且希望仅使用 Ansible 将当前在 AWS 主节点上运行的所有配置传输到多个 AWS 从节点。从节点可以是 2 个或 3 个或更多。 ansible-pull 模型是否可以在从节点的“利用率”下降或上升时自动扩展 AWS 实例?
如何分配节点的 AWS 集群?
【问题讨论】:
标签: amazon-web-services ansible ansible-pull
虽然不是直接回答,但在配置自动缩放的情况下,我使用Bootstrap Pattern。
将 git 存储库和 ansible-vault 的密钥放在 S3 上(由实例的 IAM 角色进行身份验证),并将 playbooks 放在 git 存储库中。
EC2实例的用户数据为pip install ansible、get secret key from S3、get playbook from git repository和execute 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
【讨论】:
git clone 以捕获配置。