Reputation: 741
i use this version of Ansible :
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/ychtourou/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
and i've this small playbook :
- name: play create users from var file
hosts: all
become: yes
vars_files: "vars/users.yaml"
tasks:
- name: group exists
group:
name: "{{ grp }}"
state: present
- name: user exists
user:
name: "{{ user }}"
uid: "{{ id }}"
state: present
groups: "{{ grp }}"
append: yes
the users.yaml file
user: qmerlin
id: 1000
grp: ops
the location of playbook and users.yaml file :
.
├── inventory
├── playbook1.yml
└── vars
└── users.yaml
when execute using this command ansible-playbook -i inventory playbook1.yml --ask-become-pass
i get this error :
BECOME password:
PLAY [play create users from var file] ***************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************
ok: [server1]
TASK [group exists] **********************************************************************************************************************************
fatal: [server1]: FAILED! => {"changed": false, "msg": "groupadd: '{{ grp }}' is not a valid group name\n", "name": "{{ grp }}"}
PLAY RECAP *******************************************************************************************************************************************
server1 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
it's look that Ansible is unable to get value from the file
how i can resolve that ?
Regards
Upvotes: 1
Views: 600
Reputation: 311238
You have somehow introduced the character ZERO WIDTH NON-JOINER
into your playbook. If you examine your playbook with vim
, you'll see:
- name: group exists
group:
name: "{<200c>{ grp }}"
state: present
- name: user exists
(Where <200c>
represents the character in question)
That extra character means you don't have a Jinja {{
template
marker, so you're not getting any variable substitution.
If I remove the erroneous characters from your playbook, it runs as expected.
Upvotes: 3