Hi all, first time posting, so apologies if I miss something.
I’m working on organizing an inventory folder for a multistage environment and would like verification on whether the way I expect to work is true, or if I’m missing something.
Objective
Using the following inventory folder structure:
.
├── production/
│ ├── group_vars/
│ ├── host_vars/
│ │ └── hostname-prod.fqdn.yml
│ └── inventory.ini # (contains entry for hostname-prod.fqdn)
│
├── staging/
│ ├── group_vars/
│ ├── host_vars/
│ │ └── hostname-stage.fqdn.yml
│ └── inventory.ini # (contains entry for hostname-stage.fqdn)
│
└── testing/
├── group_vars/
├── host_vars/
│ └── hostname-test.fqdn.yml
└── inventory.ini # (contains entry for hostname-test.fqdn)
I would execute a playbook (with “hosts: hostname-prod.fqdn”) to be run as follows, with the expectation that it will automatically pick up the hostname entry from the “production/inventory.ini” and the associated host variables from the “production/host_vars/hostname-stage.fqdn.yml” file:
$> ansible-playbook my-play.yml
Problem
When I try to do this, the hostname entry is indeed picked up from the “production/inventory.ini” file, however, the associated host variables aren’t picked up from the “production/host_vars/hostname-stage.fqdn.yml” file.
If I run the command as follows though, it does work:
$> ansible-playbook -i production my-play.yml
Question
Is this the correct and expected behavior? Or should my original method work without specifying “-i production”?