Ansible is ignoring my group vars, hoping I'm doing something obviously wrong...

Here is my directory structure:

`
dba.yml (a playbook)
inventory/
union.gcp.yml (a dynamic gcp inventory)
group_vars/
all/
vars.yml
vault.yml
dba/
vars.yml
roles/
someroleshere/

`

The command I’m running is
$ ansible-playbook -i inventory --vault-password-file=/path/to/file dba.yml

Ansible reads my inventory just fine and connects to correct VM. The first variable it wants is
disks

which is an array of dicts to format and mount.

Whether I put disks in the dba/vars.yml (the correct place for it to be) or all/vars.yml, Ansible gets to that variable and says it’s undefined.

I have this big messy Ansible repo where everything works but it’s a mess, that I’m starting fresh on because I read back through the docs and realized I wasn’t following any best practices, and now I’m trying to follow them to the letter and can’t get it to work.

Any help appreciated, thanks!

dba.yml (a playbook)
inventory/
  union.gcp.yml (a dynamic gcp inventory)
  group_vars/
    all/
      vars.yml
      vault.yml
    dba/
      vars.yml
roles/
  someroleshere/

$ ansible-playbook -i inventory --vault-password-file=/path/to/file dba.yml

Whether I put disks in the dba/vars.yml (the correct place for it to be) or
all/vars.yml, Ansible gets to that variable and says it's undefined.

There is nothing wrong with this

  > cat group_vars/dba/vars.yml
  disks: var from group_vars/dba/vars.yml

  > cat inventory/hosts
  [dba]
  test_01
  test_02
  test_03

  > cat dba.yml
  - hosts: dba
    tasks:
      - debug:
          var: disks

  > ansible-playbook -i inventory/hosts dba.yml

  PLAY [dba] **********

  TASK [debug] ********
  ok: [test_02] => {
      "disks": "var from group_vars/dba/vars.yml"
  }
  ok: [test_01] => {
      "disks": "var from group_vars/dba/vars.yml"
  }
  ok: [test_03] => {
      "disks": "var from group_vars/dba/vars.yml"
  }

Hello Vladimir, thank you for the response!

My understanding was that group_vars needed to be in the same directory as the inventory to work, but in your example it looks like group_vars is one directory up, is that correct?

Hi David,

To close this out, I realized from your example that in my debug statements I was putting the var in “{{}}”, which was giving me bad info and making it look like the var was undefined. Once I took it out of the quotes/curlies, I saw that the var I was trying to use was being overridden by a var provided by my host.

So thank you for the help! Problem solved!