Playbook for Windows Domain User - SomethingGeneric/sparkle.local GitHub Wiki

Ping windows hosts

  • Before you make your playbook, make sure you can successfully your windows hosts with win_ping. I find that before you put a lot of work into creating a playbook and running it, it's always good to make sure you can reach your hosts via ssh.

Troubleshooting tip for Windows SSH:

  • If you are getting an error saying that ansible cannot create a temporary directory, then add the code below into your host file.
[windows:vars] 
remote_tmp = C:\Users\ans_user\Tmp 
become_method = runas 
ansible_shell_type = powershell 
shell_type = powershell

Link: https://devops.stackexchange.com/questions/16532/ansible-playbook-fails-on-windows-server

Install microsoft.ad module

  • Check to see if you have the microsoft.ad module installed
    • ansible-galaxy collection list
  • If not, then install it via:
    • ansible-galaxy collection install microsoft.ad

image

Reference Link: https://docs.ansible.com/ansible/latest/collections/microsoft/ad/object_module.html

Make Playbook

  • Make windows_domain_user.yml file in the ansible directory.
---
- name: Create a new domain user
  hosts: dc01-sparkle
  tasks:
    - name: Ensure user is created
      microsoft.ad.user:
        identity: sparkle-daemon
        firstname: sparkle-daemon
        surname: feet
        password: user_password
        enabled: yes
        state: present
        #For verificaiton of authorized user to create account 
        domain_username: ansible
        domain_password: domain_password
        domain_server: dc01-sparkle.sparkle.local

Link to playbook

Link Referenced: https://docs.ansible.com/ansible/latest/collections/microsoft/ad/user_module.html#ansible-collections-microsoft-ad-user-module

Run Playbook

  • ansible-playbook -u sparkle-deployer -i windows_hosts.txt windows_domain_user.yml --ask-pass

image

Check User by AD

image

Check User by SSH

  • ssh sparkle-daemon@mgmt01-sparkle
  • input the password you configured in your .yml file

image