I am working with AWS instances currently and want to transfer all the configuration that is currently running on AWS master node to the multiple AWS slave nodes with Ansible only. Slave nodes may be 2 or 3 or may be more. Is it possible with the ansible-pull
model to automatically scale the AWS instance when the "Utilization" of the slave node goes down or up?
How can I assign the AWS Cluster of the Nodes?
Although it is not a direct answer, in the case of configuring auto-scale, I use Bootstrap Pattern.
Put the secret key for the git repository and ansible-vault on S3 (authenticated by IAM role of instance), and put the playbooks on git repository.
User Data of EC2 instance is pip install ansible
, get secret key from S3
, get playbook from git repository
and execute ansible-playbook
.
If there are some role of EC2 instance, you can split S3 directory and git path.
Self bootstrap mechanism make the auto-scale process more simple.
Update01: Samples
EC2 User Data Sample (not yet tested, as an image):
#!/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 Sample:
Host github-bootstrap
User git
Port 22
HostName github.com
IdentityFile /root/.ssh/git_secret_key
TCPKeepAlive yes
IdentitiesOnly yes
Update02: Most simple ver. (without S3/ansible-vault)
EC2 User Data Sample (not yet tested, as an image):
#!/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With