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:
Let's begin by setting the default variable:
#group_vars/all env_name: default
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
Let's now try running the playbook without creating the environment:
$ ansible-playbook...