Inventory folder structure verification

26 views
Skip to first unread message

john....@openbravo.com

unread,
Oct 19, 2017, 5:33:15 PM10/19/17
to Ansible Project
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"?

Brian Coca

unread,
Dec 11, 2018, 1:43:37 PM12/11/18
to Ansible Project
Im unsure of what the problem is since you seem to have contradictory
expectations, you state info should be picked from
`"production/host_vars/hostname-stage.fqdn.yml` but that file is not
under production, but under staging.

In any case you can use `ansible-inventory` to see what ansible
actually composes from the given inventory.



--
----------
Brian Coca

Tony Chia

unread,
Dec 13, 2018, 11:06:54 PM12/13/18
to Ansible Project


That is expected.

If you don’t specify -i how the ansible-playbook know you want to run against production or staging or test env ?

You could probably set some defaults using the inventory setting under defaults section in ansible.cfg. For example
https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg

I would probably organize all the inventories in one folder by moving the production, staging and test folder under an inventory folder

Then you should be able to run
Ansible-playbook -i inventory/production my-play.yml and pick up the grou_vars and host_vars

Albert Autin

unread,
Dec 13, 2018, 11:54:20 PM12/13/18
to ansible...@googlegroups.com
The behavior is the same if I specify -i ec2.py. I like to specify inventory manually instead of making it a global setting. Are you saying the yml should call the python script?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3e83bf7b-346e-424f-9612-2b99593e603c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages