Step 3: Deploy Demo Web App To Test - Alex-Burgess/ansible-demo GitHub Wiki

Now that the infrastructure is built, we need to copy the Ansible components to the Ansible Controllers. Then use Ansible with playbooks to build the webservers and deploy configuration and content at the same time.

  1. Use AWS CLI to Get Ansible Controller IPs:
    $ aws ec2 describe-instances --query 'Reservations[*].Instances[*].{PublicIpAddress:PublicIpAddress}'  --output text --filters 'Name=instance-state-name,Values=running' 'Name=tag:Type,Values=AnsibleController' 'Name=tag:Environment,Values=test' 'Name=tag:Application,Values=AnsibleDemo'
    
  2. Connect to Ansible Controller and switch to ansible user:
    $ ssh ec2-user@<ansible_public_ip>
    $ sudo -i -u ansible
    
  3. Copy Ansible files to Ansible controller:
    $ cd /app/ansible/
    $ curl -L https://github.com/Alex-Burgess/AnsibleHelloWorld/tarball/master | tar zx --wildcards "*/ansible/*" --strip-components=2
    
  4. Get Webserver IPs and update inventory file(s):
    $ aws ec2 describe-instances --query 'Reservations[*].Instances[*].{IP:PrivateIpAddress,AZ:Placement.AvailabilityZone}' --output text --filters 'Name=instance-state-name,Values=running' 'Name=tag:Type,Values=Webserver' 'Name=tag:Environment,Values=test' 'Name=tag:WebApp,Values=ansiblewebdemo'  
    
    $ cd AnsibleWebDeployment
    $ vi inventories/test/ansiblewebdemo_hosts
    
  5. Perform basic ssh test of configured servers:
    $ ansible webservers -m ping -e 'ansible_ssh_user=apache'
    
  6. Use site.yml to build webserver environment:
    $ ansible-playbook -i inventories/test/ansiblewebdemo_hosts site.yml
    
  7. Test the web application via the load balancer. Use the AWS CLI to retrieve url for test demo web app stack:
    $ aws cloudformation describe-stacks --query 'Stacks[*].Outputs[?OutputKey==`URL`].OutputValue' --output text --stack-name AnisbleWebServersDemo
    
    http://ansiblewebdemo-test-1997520045.eu-west-1.elb.amazonaws.com
    

Next: Step 4 - Make simple update to demo web application