-
Initalize the
Vagrantfile
. This will generate a file calledVagrantfile
.vagrant init --minimal
-
Copy the prepared
Vargantfile_Prepared
into the generatedVagrantfile
:cp Vargantfile_Prepared Vagrantfile
-
Spin up the VMs defined in the
Vagrantfile
:vagrant up
-
Destroy VMs:
vagrant destroy -f
- Run the Ansible playbook command using the specified configuration.
ANSIBLE_CONFIG=./ansible/ansible.cfg ansible-playbook ./ansible/main.yml
This demo shows multiple Ansible features:
- Playbooks
- Roles
- Profiling
- Conditionals
-
Spin up VMs
vagrant up
-
Configure VMs using Ansible
ANSIBLE_CONFIG=./ansible/ansible.cfg ansible-playbook ansible/main.yml
-
Check out web servers using a script:
./scripts/open_ips_in_chrome.sh
-
Change
./ansible/main.yml
to use theNginx
role.- name: Nginx Role for Dev and Prod include_role: name: nginx
-
Rerun Ansible playbook
ANSIBLE_CONFIG=./ansible/ansible.cfg ansible-playbook ansible/main.yml
-
While playbook is running add profiling to
ansible.cfg
:callbacks_enabled = timer, profile_tasks, profile_roles
-
Show that web servers are still configured the same.
-
Add conditionals in
./ansible/main.yml
:- name: Nginx Role for Dev and Prod include_role: name: nginx when: inventory_hostname != "infra" - name: Apache Role for Infra include_role: name: apache when: inventory_hostname == "infra"
-
Show that only infra is now using Apache as web server.