Create a Local Group and Users on Windows With Ansible

In this blog post, I will show you how to create a local group and two local users with Ansible on a Windows server host.

Before you start

To get this playbook working, you will need to add you Windows host to Ansible and setup a Linux control host.

You can you the following post which explains everything.

Add Windows hosts to Ansible

Setup Ansible control host on CentOS

Playbook

Below is the playbook that makes everything happen; I am creating a local group called DBA_USERS and two local users called dba01 and dba02.

– hosts: windows

tasks:

– name: Create local group

win_group:

name: DBA_USERS

description: DBA user group

– name: dba01

win_user:

name: dba01

password: SETPASSWORD

groups: DBA_USERS

– name: dba02

win_user:

name: dba02

pssword: SETPASSWORD

groups: DBA_USERS

Run Playbook

To run the playbook, I will run the following command and wait for the results.

ansible-playbook new_users.yaml

End Result

You can see the final result below, Ansible created two users and placed them inside the DBA_USERS group we created.

Processing…
Success! You're on the list.

Posted

in

by