variables in group_vars and host_vars do not load when using inventory directory

344 views
Skip to first unread message

myprogra...@gmail.com

unread,
Sep 24, 2018, 4:34:48 PM9/24/18
to Ansible Project

A playbook I ran, returned this failure:
TASK [create-admin-user : Create the non-root user account] ********************
fatal
: [415.791.30.131]: FAILED! => {"msg": "The task includes an option with an undefined variable.
The error was: 'admin_user' is undefined\n\nThe error appears to have been in '/Users/pnotes/Code/terraform/pj1/ansi/roles/create-admin-user/tasks/main.yml': line 2, column 3,
but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n---\n- name: Task 1\n  ^ here\n"
}

Given this directory structure:
├── ansible.cfg
├── inventories
  └── test
      ├── group_vars
        └── all.yml
      ├── host_vars
        └── all.yml
      └── hosts.ini
├── provision.yml
└── roles
   
└── create-admin-user
       
├── handlers
       
  └── main.yml
       
└── tasks
           
└── main.yml
Note that is directory layout follows that given in the docs


And a role defined like this:  
- name: Create the non-root user account
  user
:
    name
: "{{ admin_user.name }}"
    password
: "{{ admin_user.password | password_hash('sha512') }}"
    update_password
: on_create
   
group: sudo
    groups
: sudo
    append
: yes
    create_home
: yes
    shell
: /bin/bash


I expect the task, create-admin-user, defined above to pick variables defined in inventories/test/group_vars/all.ym and inventories/test/host_vars/all.yml  but the error messages shows that these variables aren't.

This doesn't make sense to me given that group_vars && host_vars both follow this structure:
---
admin_user
:
  name
: somename
  password
: "somepassword"
  ssh_public_key
: '/Users/pnotes/.ssh/path_to_priKey'


ansible_become_pass
: "somepasswd2"

I am bit confused as to what is happening - what am I missing? 

Message has been deleted

Brian Coca

unread,
May 1, 2020, 10:27:47 AM5/1/20
to Ansible Project
host_vars/all.yml will not affect 'all hosts', just a host named
'all'. Still the group_vars/all.yml should work, my tests do show it
working, can you provide more info like the full error and -vvv
output?

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

Reply all
Reply to author
Forward
0 new messages