khteh
khteh

Reputation: 3996

Ansible variable defined in group_vars/all not found when inventories are put in a folder

I am using ansible 2.9.7 and have the following folder structure:

/-group_vars/
     all.yml
 -inventories/
     local/localhost.yml
 -playbooks/

local/localhost.yml:

local:
  hosts:
    localhost:
      ansible_connection: local

Running ansible-playbook -i inventories/local/loaclhost.yml playbooks/playbook.yml does not pick up variables defined in group_vars/all/ What do I miss? Any advice and insight is appreciated.

Upvotes: 2

Views: 1197

Answers (1)

Rohan
Rohan

Reputation: 41

You want your group_vars/host_vars directories on the same level as your inventory files. See https://docs.ansible.com/ansible/latest/user_guide/sample_setup.html#sample-ansible-setup for details. So, you can either have:

localhost.yml                 # inventory file for localhost
group_vars/
   main.yml                   # here we assign variables to particular groups
host_vars/
   localhost.yml              # here we assign variables to particular systems
playbook.yml                  # master playbook

Or you can have

inventories/
   local/
      localhost.yml       # inventory file for production servers
      group_vars/
         main.yml         # here we assign variables to particular groups
      host_vars/
         main.yml         # here we assign variables to particular systems

   remote/
      production           # inventory file for production environment
      group_vars/
         main.yml          # here we assign variables to particular groups
      host_vars/
         prod.yml    # here we assign variables to particular systems

playbook.yml

Upvotes: 1

Related Questions