I am stuck. He left the Internet and could not find the answer.
I have been using Ansible for many years, but always with static reserves. To distinguish between different environments, such as production and production, I used different static inventory files, staging
and production
, respectively. When I needed to create intermediate servers, I would do:
ansible-playbook site.yml -i staging
When I wanted to do the same for production, I would do:
ansible-playbook site.yml -i production
Both stages of production and production require variables with different values, so I have group_vars/staging
and group_vars/production
. All is good and in line with best practices.
Now I need to provide EC2 instances in AWS. I am using this AWS guide . I have a notebook with two games. The first runs with localhost
, creates / finds the required EC2 instances in AWS, and populates the group with add_host
. The second game uses this group to run against instances of EC2 found in the first game. Everything is according to this guide.
Everything works fine except for one. I do not know how to indicate which environment to provide and, therefore, the required variables are not loaded from group_vars/(staging|production)
. Basically, what I want, like -i (staging|production)
, I have used all these years with static reserves, but it seems that using -i
now makes no sense, since the inventory is dynamic. I want to be able to load variables from group_vars/staging
or group_vars/production
based on the argument that I pass to the ansible-playbook
when I run it.
How can I do it? What is the best practice?