我目前正在使用 AWS 实例,并且希望仅使用 Ansible 将当前在 AWS 主节点上运行的所有配置传输到多个 AWS 从节点。从节点可以是 2 个或 3 个或更多。ansible-pull当从节点的“利用率”下降或上升时,模型是否可以自动扩展 AWS 实例?
如何分配节点的 AWS 集群?
我目前正在使用 AWS 实例,并且希望仅使用 Ansible 将当前在 AWS 主节点上运行的所有配置传输到多个 AWS 从节点。从节点可以是 2 个或 3 个或更多。ansible-pull当从节点的“利用率”下降或上升时,模型是否可以自动扩展 AWS 实例?
如何分配节点的 AWS 集群?
虽然不是直接回答,但在配置自动缩放的情况下,我使用Bootstrap Pattern。
将 git 存储库和 ansible-vault 的密钥放在 S3 上(由实例的 IAM 角色进行身份验证),并将剧本放在 git 存储库上。
EC2 实例的用户数据是pip install ansible、get secret key from S3和。get 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