Step 4: Make Simple Demo Web Update - Alex-Burgess/ansible-demo GitHub Wiki
To deploy updates to either content or configuration of the webservers, the processes uses the site.yml playbook exactly as before. As Ansible is idempotent, if it determines that the files have changed it will pull the changes for git and copy the files to the webservers. The web playbooks also use handlers to perform a restart if deemed necessary, e.g. in the event of a configuration update.
We'll use the ansiblewebdemo web application to demonstrate a basic workflow to make a content update. (In later pages working with git branches will be used.)
- Checkout the git repository:
git clone [email protected]:Alex-Burgess/AnsibleWebDemo.git - Make an update to a file:
cd AnsibleWebDemo/sites/helloworld.com/html vi index.php [Make changes] - Commit the changes back to the repo:
git add index.php git commit -m "Minor changes to index.php" git push - On Ansible Controller, run the playbook:
ansible-playbook -i inventories/test/ansiblewebdemo_hosts site.yml - Notice the changes made by the playbooks:
TASK [repo : get content from github for whole webapp] ****************************************************************************************************************** changed: [localhost] ... TASK [web : Synchronize all helloworld.com content] ********************************************************************************************************************* changed: [10.0.2.154] changed: [10.0.0.93] - Confirm the change to the page on one of the hosts:
http://<public-ip>
Similarly, if you make a configuration change, e.g. add an additional virtual host to the ansiblewebdemo web app apache configuration.
- Update vhost.conf with
vi webapps/ansiblewebdemo/confing/conf.d/vhost.conf [Add to bottom of file] Listen 8080 NameVirtualHost *:8080 <VirtualHost *:8080> ServerAdmin [email protected] ServerName monitoring.com ServerAlias www.monitoring.com DocumentRoot /var/www/html/monitoring.com/html/ ErrorLog /var/www/html/monitoring.com/logs/error.log CustomLog /var/www/html/monitoring.com/logs/access.log combined </VirtualHost> - Commit the changes back to the repo:
git add vhost.conf git commit -m "Adding virtual host on port 8080" git push - On Ansible Controller, run the playbook:
ansible-playbook -i inventories/test/ansiblewebdemo_hosts site.yml - Notice the changes made by the playbooks, and this time with restart::
TASK [web : Synchronize web farm conf.d directory] ********************************************************************************************************************** changed: [10.0.2.154] changed: [10.0.0.93] RUNNING HANDLER [web : restart apache] ********************************************************************************************************************************** changed: [10.0.2.154] changed: [10.0.0.93] - Confirm the change to the configuration on one of the hosts:
http://<public-ip>:8080