Windows Playbook Fails Using win_user

31 views
Skip to first unread message

Anfield

unread,
Aug 11, 2016, 10:47:37 AM8/11/16
to Ansible Project
Trying to run a playbook to add a user on a windows server and getting errors, see below

[root@localhost group_vars]# ansible-playbook createuser.yml
ERROR! Syntax Error while loading YAML.

The error appears to have been in '/etc/ansible/group_vars/createuser.yml': line 2, column 1, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:
- name: Add a user
hosts: all
^ here

I have a /etc/ansible/group_vars/windows.yml setup as follows
ansible_ssh_user: Administrator
ansible_ssh_pass: Liverpool27
ansible_ssh_port: 5986
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

I have a /etc/ansible/group_vars/createuser.yml as follows

- name: Add a user
hosts: all
gather_facts: false
tasks:
- name: Add User
win_user:
name: ansible1
password: "@ns1bl3"
state: present
groups: ["Users"]

Also have a hosts file setup under /etc/ansible/hosts

[windows]
10.10.128.0

When I run the command manually with the one liner it works fine - 
ansible windows --module-name=win_user --args="name=ansible password=fooBar1+3"

If I try and run it with the following it still doesnt work ->  ansible-playbook -i 10.10.128.0 createuser.yml

Suggestions welcome... Thanks

Matt Davis

unread,
Aug 11, 2016, 12:49:48 PM8/11/16
to Ansible Project
Unless it's just Google Groups eating the formatting, it looks like your YAML indentation is hosed up (Ansible's failing on the control side, not on the Windows module). YAML is whitespace-sensitive, so it should look like:

- name: Add a user
  hosts: all
  gather_facts: false
  tasks:
  - name: Add User
    win_user:
      name: ansible1
      password: "@ns1bl3"
      state: present
      groups: ["Users"]


Anfield

unread,
Aug 11, 2016, 1:36:24 PM8/11/16
to Ansible Project
That was perfect. Thanks! 
Reply all
Reply to author
Forward
0 new messages