# Undefined Variable

**URL:** <https://forum.ansible.com/t/undefined-variable/37593>\
**Category:** Ansible Project\
**Created:** [January 30, 2023, 3:40pm UTC](https://forum.ansible.com/t/undefined-variable/37593 "2023-01-30T15:40:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [January 30, 2023, 3:40pm UTC](https://forum.ansible.com/t/undefined-variable/37593/1 "2023-01-30T15:40:57Z")

</div>

Hello All,

I need help with and undefined variable in my Ansible Role! Any help will be appreciated!

Ansible Version

ansible 2.9.27  
config file = /home/kjames/ansible.cfg  
configured module search path = [u’/home/kjames/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]  
ansible python module location = /usr/lib/python2.7/site-packages/ansible  
executable location = /usr/bin/ansible  
python version = 2.7.5 (default, Jun 28 2022, 15:30:04) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

Configuration

ansible-config dump --only-changed  
DEFAULT\_BECOME(/home/kjames/Ansible/ansible.cfg) = True  
DEFAULT\_BECOME\_ASK\_PASS(/home/kjames/Ansible/ansible.cfg) = False  
DEFAULT\_BECOME\_METHOD(/home/kjames/Ansible/ansible.cfg) = sudo  
DEFAULT\_BECOME\_USER(/home/kjames/Ansible/ansible.cfg) = root  
DEFAULT\_HOST\_LIST(/home/kjames/Ansible/ansible.cfg) = [u’/home/kjames/Ansible/static-ini-inventory’]  
DEFAULT\_REMOTE\_USER(/home/kjames/Ansible/ansible.cfg) = kjames

OS / Environment

CentOS Linux release 7.9.2009 (Core)

$ ansible-playbook ansible-playbooks/create-user.yml

PLAY [node1] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node1]

TASK [create-user : Adding new user] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [node1]

TASK [create-user : Adding user to sudoers] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [node1]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘user\_name’ is undefined\n\nThe error appears to be in ‘/home/kjames/Ansible/ansible-playbooks/roles/create-user/tasks/main.yml’: line 7, 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: Adding user to sudoers\n ^ here\n”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
node1 : ok=2 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 30, 2023, 3:43pm UTC](https://forum.ansible.com/t/undefined-variable/37593/2 "2023-01-30T15:43:37Z")

</div>

We would need to see the playbook and role included.

Walter

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [January 30, 2023, 3:51pm UTC](https://forum.ansible.com/t/undefined-variable/37593/3 "2023-01-30T15:51:10Z")

</div>

Forgot to add!

Playbook:

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 30, 2023, 4:20pm UTC](https://forum.ansible.com/t/undefined-variable/37593/4 "2023-01-30T16:20:18Z")

</div>

Are you setting a value for user\_name? See red below.

Walter

---

<div class="post-metadata">

**Author:** ![Keith\_Mills](https://avatars.discourse-cdn.com/v4/letter/k/b77776/32.png) [@Keith\_Mills](https://forum.ansible.com/u/Keith_Mills)\
**Post date:** [January 30, 2023, 4:57pm UTC](https://forum.ansible.com/t/undefined-variable/37593/5 "2023-01-30T16:57:36Z")

</div>

How do I set a value?

---

<div class="post-metadata">

**Author:** ![Walter\_Rowe](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/walter_rowe/32/4506_2.png) [@Walter\_Rowe](https://forum.ansible.com/u/Walter_Rowe)\
**Post date:** [January 30, 2023, 6:28pm UTC](https://forum.ansible.com/t/undefined-variable/37593/6 "2023-01-30T18:28:18Z")

</div>

It is your playbook. You have to figure that out.

Walter
