Manage multiple environments using Ansible
-
Clone this repository:
git clone https://github.com/mbigras/ansible-example cd ansible-example
-
Start the
srv1.site1.egfast.com
Vagrant machine forsite1
in thedev
environment:vagrant up /site1/
- Each environment can contain multiple sites.
- Each site can contain multiple machines.
-
Run an Ansible adhoc command:
ansible -i dev.ini site1 -m ping
This command uses the following options and argument:
-i
- Ansible inventory. The development, quality assurance, and production environments are organized and isolated into the separate files.site1
- Pattern for the site to target.-m
- Ansible module to execute. This command executs the Ansible Ping module. It's not an ICMP ping. This is just to check if Ansible is working.
-
Run an Ansible playbook:
ansible-playbook -i dev.ini -l site1 playbooks/ping.yml
Gotcha: The
ansible-playbook
command uses the same pattern as theansible
command but uses the-l
flag. -
Destroy the
srv1.site1.egfast.com
Vagrant machine:vagrant destroy -f /site1/