4
votes

I have two Ansible projects. One contains common roles and playbooks, the second playbooks, roles specific to a customer including the inventory.

I want to be able to run the common playbooks using the inventory from the second project

ansible-playbook -vvvv -s -K -i \
    ~/inventory/hosts/staging.int.openbet.com site.yml

~/inventory >
.
├── group_vars
│   └── all
├── hosts
│   └── staging.int.openbet.com
└── host_vars
    └── staging.int.openbet.com

This runs against the host correctly but the host_vars aren't picked up. I was expecting the host_vars and group_vars to be relative to the inventory file but this doesn't seem to happen.

http://docs.ansible.com/intro_inventory.html#splitting-out-host-and-group-specific-data

Tip: In Ansible 1.2 or later the group_vars/ and host_vars/ directories can exist in either the playbook directory OR the inventory directory. If both paths exist, variables in the playbook directory will be loaded second.

Any help most appreciated, i'm running 1.7

1
Believe the issue was the extra hosts directory. Just checking nowJames Morgan
For posterity: yup, imagine you're in the working directory as the hosts file, Ansible is looking for ./group_vars and ./host_vars directories from there. So moving that hosts file to ~/inventory/staging.int.openbet.com would let it find the missing variables.nikobelia

1 Answers

1
votes

You need to define the inventory file path in ansible.cfg in your first project where you will define the path of inventory from the second project.

Example:

inventory = ./_inventory/hosts.ini