I have two inventory files, staging and production.
staging contents:
[server]
192.168.56.101 #server 1
192.168.56.103 #server 2
production contents:
[server]
192.168.56.108 #server test
I have two inventory files, staging and production.
staging contents:
[server]
192.168.56.101 #server 1
192.168.56.103 #server 2
production contents:
[server]
192.168.56.108 #server test
You can put both staging and production inventories in a folder, inventory, and call ansible-playbook -i inventory/ and both sets of hosts will be available to you.
If you use hosts: all anywhere in your playbook, this might not work, since it will target both environments. In that case I do hosts: “{{hosts}}” and specify the target on the command line
ansible-playbook - inventory/ -e hosts=staging
I changed the structure by following this tutorial , because I need staging and production have different database configuration. I still had the same issue with it.
new structure :
roles
production
–|group_vars
----|server.yml
–|inventory
staging
–|group_vars
----|server.yml
–|inventory