Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Advanced Features in Ansible Playbooks

There are a number of features unique to Ansible playbooks which provide robust functionality. This exercise explores many of these features in a practical scenario of deploying a web server. Most notably, this exercise deals with confidential data in an Ansible vault and working with tags in Ansible playbooks.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 1h 30m
Published
Clock icon Apr 05, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Use ansible-vault to protect the confidential information.

    Use ansible-vault to encrypt /home/ansible/confidential to protect the confidential information stored within using the password "I love ansible".

    Run ansible-vault encrypt /home/ansible/confidential and supply the password "I love ansible".

  2. Challenge

    Create a playbook that deploys httpd on webservers.

    Create a playbook in /home/ansible/webserver.yml that deploys httpd on webservers. It should be tagged with base-install and contain a handler that restarts the httpd daemon that is flagged by both installation and service manipulation for httpd.

    Create the file /home/ansible/webserver.yml and add the following content:

    - hosts: webservers
      become: yes
      vars_files:
        - /home/ansible/confidential
      tasks:
        - name: install httpd
          yum:
            name: httpd
            state: latest
          notify: httpd service
          tags:
            - base-install
      handlers:
        - name: Restart and enable httpd
          service:
            name: httpd
            state: restarted
            enabled: yes
          listen: httpd service
    
  3. Challenge

    Deploy the templates stored on the control node to the webservers group.

    Configure /home/ansible/webserver.yml to deploy the templates /home/ansible/vhost.conf.j2 and /home/ansible/htpasswd.j2 stored on the control node to the webservers group. httpd must restart on config change. The tasks should be tagged vhost.

    Add the following text to /home/ansible/webserver.yml just before the handler section:

        - name: configure virtual host
          template:
            src: /home/ansible/vhost.conf.j2
            dest: /etc/httpd/conf.d/vhost.conf
          notify: httpd service
          tags:
            - vhost
        - name: configure site auth
          template:
            src: /home/ansible/htpasswd.j2
            dest: /etc/httpd/conf/htpasswd
          notify: httpd service
          tags:
            - vhost
    
  4. Challenge

    Asynchronously execute data-job on webservers.

    Configure /home/ansible/webserver.yml to asynchronously execute /opt/data-job.sh located on webservers with a timeout of 600 seconds and no polling. The task should be tagged with data-job.

    Add the following text to /home/ansible/webserver.yml just before the handler section: - name: run data job command: /opt/data-job.sh async: 600 poll: 0 tags: - data-job

  5. Challenge

    Execute playbook to verify your playbook works correctly.

    Execute playbook /home/ansible/webserver.yml to verify your playbook works correctly.

    Run ansible-playbook --ask-vault-pass /home/ansible/webserver.yml from the control node providing the vault password "I love ansible".

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans