Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ansible Playbook Essentials

You're reading from   Ansible Playbook Essentials Design automation blueprints to manage your multitier infrastructure

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781784398293
Length 168 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Gourav Shah Gourav Shah
Author Profile Icon Gourav Shah
Gourav Shah
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface Setting Up the Learning Environment FREE CHAPTER 1. Blueprinting Your Infrastructure 2. Going Modular with Ansible Roles 3. Separating Code and Data – Variables, Facts, and Templates 4. Bringing In Your Code – Custom Commands and Scripts 5. Controlling Execution Flow – Conditionals 6. Iterative Control Structures – Loops 7. Node Discovery and Clustering 8. Encrypting Data with Vault 9. Managing Environments 10. Orchestrating Infrastructure with Ansible A. References
Index

Creating a development environment


After learning about how to manage environments, let's try it out by refactoring our existing code and create a dev environment. To test it, let's create a variable called "env_name" and change the default page of Nginx to dynamically use this variable and print the environment name. We will then try to override this variable from the environment. Let's take a look at the following steps:

  1. Let's begin by setting the default variable:

    #group_vars/all
    env_name: default
  2. Then, change the Nginx task to use a template instead of a static file, so make the following modification in the roles/nginx/tasks/configure.yml file:

     - name: create home page for default site
        copy: src=index.html dest=/usr/share/nginx/html/index.html

    Modify it into the following code:

     - name: create home page for default site
       template:
         src: index.html.j2
         dest: /usr/share/nginx/html/index.html
  3. Let's now try running the playbook without creating the environment:

    $ ansible-playbook...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime