Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

I have a doubt in Ansible, could some one help me to resolve.

—————-

├── ansible.cfg

├── environments/         # Parent directory for our environment-specific directories

│   │

│   ├── dev/              # Contains all files specific to the dev environment

│   │   ├── group_vars/   # dev specific group_vars files

│   │   │   ├── all

│   │   │   ├── db

│   │   │   └── web

│   │   └── hosts         # Contains only the hosts in the dev environment

│   │

│   ├── prod/             # Contains all files specific to the prod environment

│   │   ├── group_vars/   # prod specific group_vars files

│   │   │   ├── all

│   │   │   ├── db

│   │   │   └── web

│   │   └── hosts         # Contains only the hosts in the prod environment

│   │

│   └── stage/            # Contains all files specific to the stage environment

│       ├── group_vars/   # stage specific group_vars files

│       │   ├── all

│       │   ├── db

│       │   └── web

│       └── hosts         # Contains only the hosts in the stage environment

├── playbook.yml

Above is my playbook.yml

the script works fine when i pass the specific environment name

for example:

ansible-playbook script.yml -i dev

i want to run this playbook for all the environments for the same playbook.

how to do that?

1 Answer

0 votes
by (50.2k points)
Please to inform you that you can run all the environments using single playbook, Here we will provide you with an example and then you need to use that type of syntax, That example we are taking is an example where there are multiple roles(ansible-roles), and we are trying to run different roles in a single playbook.
Example:
sudo nano site.yml
---
- hosts: slave1
sudo: yes
roles:
- role_apache
---
- hosts: slave2
sudo: yes
roles:
   - role_nginx
The similar way you need to use your environments, instead of running the environments seperately add the commands in a single playbook, and try to run that particular playbook then you will get the desired output. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...