2.1.1. Deploy Web Applications

You will create a playbook to deploy applications to previously provisioned webservers.

As a reminder, the following assumes that you are using RDP to access the Jump host provided for this lab, that you are SSH’d into the “Ansible” host and that the current working directory in that session is /root/f5-ansible-workshop.

Examine ansible inventory file

Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in Ansible’s inventory. For this lab, the ansible inventory file is inventory/hosts.

  1. Edit ansible inventory file and ensure it has the entries listed below. This lab is written for use with nano editor but you may substitute with vi or vim.

    • Type nano inventory/hosts and modify if necessary
    • Type the following into the inventory/hosts file
    [bigips]
    10.1.1.245
    
    [appservers]
    10.1.20.17 ansible_user=root
    10.1.20.20 ansible_user=root
    
    [webservers]
    10.1.20.15 ansible_user=root
    10.1.20.16 ansible_user=root
    
    • Type ctrl x then press enter to save file.

Create Playbook to deploy web application

  1. Create a playbook newapp.yaml.

    • Type nano playbooks/newapp.yaml
    • Type the following into the playbooks/newapp.yaml file.
    ---
    
    - name: Deploy newapp
      hosts: webservers
      vars:
        valid_certs: no
    
      tasks:
        - name: deploy to server5
          copy:
            src: ../files/f5-hello-world-develop/customizations/blue.css
            dest: /var/www/server/5/css/custom.css
          tags: serv5
    
        - name: deploy to server6
          copy:
            src: ../files/f5-hello-world-develop/customizations/green.css
            dest: /var/www/server/6/css/custom.css
          tags: serv6
    
    • Type ctrl x and save file.
  2. Run this playbook to copy files from ansible host to destination webservers.

    • Type ansible-playbook playbooks/newapp.yaml

    If successful, you should see similar results

    ../../_images/image011.png
  3. Verify results by browsing to websites.

    • Type curl http://10.1.20.15 --silent | grep SERVER_NAME
    • Type curl http://10.1.20.16 --silent | grep SERVER_NAME
    ../../_images/image011a.png

    Note

    The hosts: webservers referenced in the playbook are defined in the inventory/hosts file. These webservers are on an internal vlan and not typically accessible by external users. Upon successful deployment of the applications, app owners typically submit request for NetOps to configure app services such as dns, load balancing and firewall, before these applications can be accessed externally.