ansible-examples icon indicating copy to clipboard operation
ansible-examples copied to clipboard

AnsibleUndefinedVariable

Open mbettan opened this issue 10 years ago • 6 comments

Hello all,

I have following error when I apply playbook for each one

{'msg': "AnsibleUndefinedVariable: One or more undefined variables: 'http_port' is undefined", 'failed': True}

Could you please explain how to configure those variables ? It would be great to add a note in the readme.

Thanks for help

mbettan avatar Nov 03 '15 00:11 mbettan

create a file called main.yml in roles/tomcat/vars and include ' http_port=<port_no.>'

rashbhat avatar Mar 10 '16 11:03 rashbhat

@rashbhat : how can i pass the host info using dynamic inventory? any thoughts?

#ansible-pull -d /home/gvenka008c/reponame --key-file=/home/users/rsa.id -U [email protected]:reponame.git playbook.yml

[WARNING]: provided hosts list is empty, only localhost is available

gvenka008c avatar Mar 15 '16 19:03 gvenka008c

TASK [tomcat : Configure Tomcat server] *************************************************************************************************************************************
task path: /root/ansible-examples/tomcat-standalone/roles/tomcat/tasks/main.yml:25
fatal: [Git]: FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "AnsibleUndefinedVariable: 'http_port' is undefined"
}
fatal: [jenkin]: FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "AnsibleUndefinedVariable: 'http_port' is undefined"
}
fatal: [nagios]: FAILED! => {
    "changed": false,
    "failed": true,
    "msg": "AnsibleUndefinedVariable: 'http_port' is undefined"
}
        to retry, use: --limit @/root/ansible-examples/tomcat-standalone/site.retry

PLAY RECAP ******************************************************************************************************************************************************************
Git                        : ok=11   changed=0    unreachable=0    failed=1
jenkin                     : ok=11   changed=0    unreachable=0    failed=1
nagios                     : ok=11   changed=0    unreachable=0    failed=1


[root@centos var]# cat main.yml
#re variables related to the Tomcat installation

include : http_port:8080
include : https_port:8443

# This will configure a default manager-gui user:
#
# admin_username: admin
# admin_password: adminsecret
#
[root@centos var]# pwd
/root/ansible-examples/tomcat-standalone/roles/tomcat/var
[root@centos var]#

I created file under create a file called main.yml in roles/tomcat/vars . Please help me to fix this error!

fahdkecheri avatar Jul 21 '17 12:07 fahdkecheri

Hi,

I have resolved the issue as below Steps

  1. Create 'vars' directory in roles/tomcat
[root@instance-1 vars]# pwd
/home/user/ansible-tomcat/roles/tomcat/vars
  1. Copy the group_vars/tomcat-servers file to /roles/tomcat/vars/main.yml file
[root@instance-1 vars]# cat main.yml 
# Here are variables related to the Tomcat installation

http_port: 8086
https_port: 8443

# This will configure a default manager-gui user:

admin_username: admin
admin_password: adminsecret

syamv avatar Mar 26 '18 08:03 syamv

Thanks It worked :)

himaja-ala avatar Apr 16 '18 06:04 himaja-ala

syamv -I faced the same issue and followed the same which you posted above. issue no more persisting.. but wanted to know why it is not taking the vars from group_vars folder wanted to know that can some one explain me

sreekanth564 avatar Aug 25 '19 10:08 sreekanth564