I am new to Ansible and not very versed to Linux in general so this is probably quite basic question but it makes me scratch my head quite for some time. Debugging with several levels of verbosity, Googling for problem nor study of several tutorials didn´t provide an answer nor hint what is wrong. But to my issue:
I tryied to use roles for reusability. I manually made folders tasks and roles directly under /etc/ansible/roles on my DEV machine. But after decomposing original playbook into role it stared failing with error The task includes an option with an undefined variable. The error was: 'groups_additional' is undefined.
My decomposed files:
playbook test_user.yml
---
- hosts: test_host
remote_user: test
gather_facts: no
roles:
- user
vars:
user_name: test
user_pwd: <secret>
group_name: test_grp
roles/user/tasks/main.yml ############ Error happens here in groups
---
- name: Check '{{ user_name }}' user, set his pwd and groups
ansible.builtin.user:
name: '{{ user_name }}'
password: '{{ user_pwd }}'
group: '{{ user_name if group_name is undefined else group_name }}'
groups: '{{ user_name if group_name is undefined else group_name }} {{ groups_additional if groups_additional is defined }}'
become: yes #use sudo
roles/user/vars/main.yml
---
groups_additional: ', qwqe'
Please, note that this is really simplified version of my playbook but with important places presented.