Ansible group_vars not loading or am I making a fundamental mistake here?

1,578 views
Skip to first unread message

Satish Muthali

unread,
May 15, 2015, 9:25:47 AM5/15/15
to ansible...@googlegroups.com
Hello experts,
This is the following ansible directory structure I have:

├── environments                                 
│   └── azure_sandbox                            
├── filter_plugins                               
├── group_vars                                   
│   ├── all.yml                                  
│   └── uswest_sandbox.yml                       
├── hierarchy.README                             
├── host_vars                                    
├── library                                      
├── roles                                        
│   ├── cassandra                                
│   ├── common                                   
│   │   ├── default                              
│   │   ├── files                                
│   │   ├── handlers                             
│   │   │   └── main.yml                         
│   │   ├── meta                                 
│   │   ├── tasks                                
│   │   │   ├── Debian.yml                       
│   │   │   ├── docker_base_centos7.yml          
│   │   │   ├── main.yml                         
│   │   │   ├── RedHat.yml                       
│   │   │   ├── rh6.yml                          
│   │   │   ├── rh7.yml                          
│   │   │   ├── rh_java.yml                      
│   │   │   └── rh_pytools.yml                   
│   │   ├── templates                            
│   │   │   ├── docker-defaults.j2               
│   │   │   └── docker-init.j2                   
│   │   └── vars                                 
│   │       └── main.yml                         
│   ├── docker                                   
│   │   ├── handlers                             
│   │   │   └── main.yml                         
│   │   ├── meta                                 
│   │   ├── tasks                                
│   │   │   ├── Debian.yml                       
│   │   │   ├── main.yml                         
│   │   │   ├── RedHat.yml                       
│   │   │   ├── rh6.yml                          
│   │   │   ├── rh7.yml                          
│   │   │   └── rh_pytools.yml                   
│   │   ├── templates                            
│   │   │   ├── docker-defaults.j2               
│   │   │   └── docker-init.j2                   
│   │   └── vars                                 
│   │       └── main.yml                         
│   ├── elasticsearch                            
│   ├── kafka                                    
│   ├── netty                                    
│   ├── nginx                                    
│   │   ├── handlers                             
│   │   │   └── main.yml                         
│   │   ├── meta                                 
│   │   ├── tasks                                
│   │   │   ├── Debian.yml                       
│   │   │   ├── main.yml                         
│   │   │   ├── RedHat.yml                       
│   │   │   ├── rh6.yml                          
│   │   │   └── rh7.yml                          
│   │   ├── templates                            
│   │   │   ├── docker-defaults.j2               
│   │   │   └── docker-init.j2                   
│   │   └── vars                                 
│   │       └── main.yml                         
│   ├── storm_deploy                             
│   ├── storm_supervisor                         
│   └── zookeeper                                
└── top_level_playbooks                          
    ├── top_level_base.yml                       
    ├── top_level_docker.yml                     
    └── top_level_java.yml                       

Here's the inventory file:

# uswest: sandbox: UI
[sandbox_webtier_uswest]
<redacted>
#----------------------------------------

# uswest: sandbox: REST Layer
[sandbox_resttier_uswest]
<redacted>
#----------------------------------------

# uswest: sandbox: Processing Layer: Kafka
#-----------------------------------------
[sandbox_kafka_uswest]
<redacted>

# uswest: sandbox: Processing Layer: Storm
#------------------------------------------
[sandbox_storm_uswest]
<redacted>

# uswest: sandbox: Processing Layer: Zookeeper
#--------------------------------------------
[sandbox_zk_uswest]
<redacted>

# uswest: sandbox: Processing Layer Main
#----------------------------------------
[sandbox_processingtier_uswest:children]
sandbox_kafka_uswest
sandbox_storm_uswest
sandbox_zk_uswest

# uswest: sandbox: Storage Layer: Cassandra
#------------------------------------------
[sandbox_cass_uswest]
<redacted>

# uswest: sandbox: Storage Layer: Elasticsearch
# ----------------------------------------------
[sandbox_es_uswest]
10.0.4.5

# uswest: sandbox: Storage Layer Main
# ------------------------------------
[sandbox_storagetier_uswest:children]
sandbox_cass_uswest
sandbox_es_uswest

# uswest: sandbox: Main
# ----------------------
[uswest_sandbox:children]
sandbox_webtier_uswest
sandbox_resttier_uswest
sandbox_processingtier_uswest
sandbox_storagetier_uswest

Now, I have defined group_vars for "uswest_sandbox" group of groups in the group_vars folder
# group_vars/uswest_sandbox
---
registryurl: <redacted>
registry: <redacted>
registrySeparator: <redacted>"
registryUser:<redacted>
registryPass: <redacted>
registryEmail: <redacted>
userName:<redacted>

With this, when I run the ansible playboox, the group_vars/uswest_sandbox is not loaded/read.

Here's the yml file in /roles/common/tasks where I am referring the vars

- name: "Perform docker login to registry running on sandbox-bastion node"
  shell: docker login --username={{ registryUser }} --password={{ registryPass }} --email={{ registryEmail }} {{ registryurl }}

So, I would expect Anisble to look for the vars in the local vars folder i.e. roles/common/vars, and then look at top level directory i.e. group_vars/uswest_sandbox.yml
However ansible run gives the following error: 
"One or more undefined variables: 'registryUser' is undefined"


I might me off with my understanding here. Any help is appreciated.

Ansible version:
ansible 1.9.1
  configured module search path = /opt/ansible_cradle/custom_modules

Thanks
Satish

Brian Coca

unread,
May 15, 2015, 10:16:13 AM5/15/15
to ansible...@googlegroups.com
group/host vars need to be relative to either the inventory or the
playbook, you seem to have them in a directory above both, ansible has
no reason to look there. You will have the same problem with your
'library' dir which I assume you want to use for custom modules, it
must be adjacent to your plays or inside the role that uses them or is
loaded in your play.




--
Brian Coca

Satish Muthali

unread,
Jun 1, 2015, 5:57:09 PM6/1/15
to ansible...@googlegroups.com
Thanks Brain, you were spot on. Sorry for the late reply. I realized my mistake once I had posted the question.

-Satish
Reply all
Reply to author
Forward
0 new messages