First you will need to set be Ansible.
If you are using ubuntu, read Install Ansible on ubuntu EC2.
If you are using a Mac, read Installing and Running Ansible on Mac OSX and pinging ec2 machines.
You must:
- have python boto installed
- set up the AWS access keys in the environment settings
Adding a host
We will use the ec2 module. It runs against localhost, so we will add a host entry.
vi /etc/ansible/hosts
Append the following:
localhost ansible_connection=local
Launching a micro instance
Label this launch_playbook.yml
Execute the script.
ansible-playbook launch_playbook.ymlIn your AWS EC2 console, you will see an instance named ansible. Each task is executed in sequence.
Now add this new host in the ansible host file and label it webservers.
vi /etc/ansible/hosts
[webservers]
{the_ip_of_ec2_instance_we_just_created} ansible_connection=ssh ansible_ssh_user=ec2-user ansible_ssh_private_key_file={path_to_aws_private_key}
You don't have to do the above. In fact, you can use the group name "ec2-servers" for the following script. But the following script will need to be in the same file as the first script. I am just separating these files for easier configuration in the future.
Installing php, nginx, mysql
Label this configure_playbook.yml
Execute the script.
Remember to terminate the instance when you finish, else it will incur charges.
Execute the script.
ansible-playbook configure_playbook.ymlGo to the public address of this instance. You should see the nginx welcoming message.
Remember to terminate the instance when you finish, else it will incur charges.
No comments:
Post a Comment